Spaces:
Sleeping
Sleeping
Download code/train-model.py from shoupjom01/vehicle: direct link, hf CLI and curl.
- Browser
- Download file 749 Bytes
-
https://huggingface.co/spaces/shoupjom01/vehicle/resolve/main/code/train-model.py
- Command line
-
hf download hf://spaces/shoupjom01/vehicle/code/train-model.py
-
curl -L -o train-model.py https://huggingface.co/spaces/shoupjom01/vehicle/resolve/main/code/train-model.py
749 Bytes
| from pathlib import Path | |
| from fastai.vision.all import * | |
| if __name__ == '__main__': # Add this block to handle multiprocessing on Windows | |
| path = Path('images') | |
| dls = DataBlock( | |
| blocks=(ImageBlock, CategoryBlock), | |
| get_items=get_image_files, | |
| splitter=RandomSplitter(valid_pct=0.2, seed=42), | |
| get_y=parent_label, | |
| item_tfms=[Resize(192, method='squish')] | |
| ).dataloaders(path, bs=32) | |
| print("Dataloader defined") | |
| learn = vision_learner(dls, resnet18, metrics=error_rate) | |
| print("Learning complete") | |
| learn.fine_tune(3) | |
| print("Fine tuning complete") | |
| #learn.save("bird-or-forest-model") | |
| learn.export("./model/vehicles.pkl") | |
| print("Saved model as: vehicles.pkl") | |