This model is a simple model that classifies images of clothes in 10 classes. The model is trained with the dataset FashionMNIST.
All things in this example are customized. There are some files:
model.py
: contains the arch's modelhandler.py
: contains the handler that manage your data thus handles pre-processing-post of dataparameters.pt
: contains the state_dict of the model created withtorch.save(model.state_dict(), 'parameters.pt')
checkpoint.pt
: contains the checkpoint of the model created withtorch.save(model, 'checkpoint.pt')
script_module.pt
andtrace_module.pt
: are two files created respectively bytorch.jit.script(model, 'script_module.pt')
andtorch.jit.trace(model, 'trace_module.pt')
that are used in case of TorchScript mode
torch-model-archiver -f --model-name fashion --version 1.0 --handler ./customized_example/handler.py --model-file ./customized_example/model.py --serialized-file ./customized_example/parameters.pt --export-path ./model_store/
torchserve --start --model-store model_store --ncs
curl -X POST "http://localhost:8081/models?url=fashion.mar&model_name=fashion&model_version=1.0&handler=handler.py&batch_size=1&max_batch_delay=5000&initial_workers=1&synchronous=true"
In directory /img
there are some images that you can use to test the model. You can use curl
to get an inference from Torchserve:
curl "http://localhost:8080/predictions/fashion" -T ./customized_example/img/test1.jpg
If you want use file download.ipynb
to download other images from the web. In first you have to install jupyter
and ipykernel
.