← Back to list

【macOS Sonoma 14.1.2】Image Classification on Custom Dataset using Vision Transformer on MacBook Pro

14-inch MacBook Pro with M3 Pro

yuhsi chen · 2024-01-23 11:49 · 0 claps · 1.3 min read
#macos #classification #vit #vision-transformer #m3-pro
Open on Medium ↗
Wiki topics: ML · Machine Learning

【macOS Sonoma 14.1.2】Image Classification on Custom Dataset using Vision Transformer on MacBook Pro with M3 Pro

14-inch MacBook Pro with M3 Pro

1️⃣Create conda environment 2️⃣Clone official repository and install required packages 3️⃣Download pretrained weight 4️⃣Train on custom dataset using CPU 5️⃣Evaluate on validation dataset Acknowledgments and References

1️⃣Create conda environment

$ conda create -n vit python=3.9 -y
$ conda activate vit

↪Back to the content⤴

2️⃣Clone repository and install required packages

$ git clone https://github.com/jeonsworld/ViT-pytorch.git
$ cd ViT-pytorch/
$ pip install -r requirements.txt
$ pip install packaging
$ pip install scipy
$ pip install torchvision
$ pip install scikit-learn
$ pip install matplotlib
$ pip install ttach
$ pip install ml-collections
$ pip install opencv-python
$ brew install wget

↪Back to the content⤴

3️⃣Download pretrained weight

$ mkdir checkpoint
$ cd checkpoint/
$ wget https://storage.googleapis.com/vit_models/imagenet21k+imagenet2012/ViT-B_16.npz

↪Back to the content⤴

4️⃣Train on custom dataset using CPU

# Too many open files error when training in loop
$ ulimit -n unlimited
$ python train.py --name orchid --dataset orchid --train_batch_size 4 --model_type ViT-B_16 --pretrained_dir checkpoint/ViT-B_16.npz --img_size 640 --learning_rate 3e-2 --output_dir output_ulimit

↪Back to the content⤴

5️⃣Evaluate on validation dataset

$ python val.py --model_type ViT-B_16 --checkpoint output/orchid_checkpoint_b4.bin --img_size 416 --test_dir ../training/val/

↪Back to the content⤴

Acknowledgments and References

↪Back to the content⤴


메타데이터
post_id
2d69714350fa
slug
macos-sonoma-14-1-2-image-classification-on-custom-dataset-using-yolov8-on-macbook-pro-with-m3-pro-2d69714350fa
url
https://medium.com/@scofield44165/macos-sonoma-14-1-2-image-classification-on-custom-dataset-using-yolov8-on-macbook-pro-with-m3-pro-2d69714350fa
canonical_url
https://medium.com/@scofield44165/macos-sonoma-14-1-2-image-classification-on-custom-dataset-using-yolov8-on-macbook-pro-with-m3-pro-2d69714350fa
author_url
https://medium.com/@scofield44165
status
ok
fetched_at
2026-07-24 13:27:28