Views
No views yet
pip install pyrovisionconda install -c pyronear pyrovision1git clone https://github.com/pyronear/pyro-vision.git
2pip install -e pyro-vision/.1from PIL import Image
2from torchvision.transforms import Compose, ConvertImageDtype, Normalize, PILToTensor, Resize
3from torchvision.transforms.functional import InterpolationMode
4from pyrovision.models import model_from_hf_hub
5
6model = model_from_hf_hub("pyronear/mobilenet_v3_small").eval()
7
8img = Image.open(path_to_an_image).convert("RGB")
9
10# Preprocessing
11config = model.default_cfg
12transform = Compose([
13 Resize(config['input_shape'][1:], interpolation=InterpolationMode.BILINEAR),
14 PILToTensor(),
15 ConvertImageDtype(torch.float32),
16 Normalize(config['mean'], config['std'])
17])
18
19input_tensor = transform(img).unsqueeze(0)
20
21# Inference
22with torch.inference_mode():
23 output = model(input_tensor)
24probs = output.squeeze(0).softmax(dim=0)1@article{DBLP:journals/corr/abs-1905-02244,
2 author = {Andrew Howard and
3 Mark Sandler and
4 Grace Chu and
5 Liang{-}Chieh Chen and
6 Bo Chen and
7 Mingxing Tan and
8 Weijun Wang and
9 Yukun Zhu and
10 Ruoming Pang and
11 Vijay Vasudevan and
12 Quoc V. Le and
13 Hartwig Adam},
14 title = {Searching for MobileNetV3},
15 journal = {CoRR},
16 volume = {abs/1905.02244},
17 year = {2019},
18 url = {http://arxiv.org/abs/1905.02244},
19 eprinttype = {arXiv},
20 eprint = {1905.02244},
21 timestamp = {Thu, 27 May 2021 16:20:51 +0200},
22 biburl = {https://dblp.org/rec/journals/corr/abs-1905-02244.bib},
23 bibsource = {dblp computer science bibliography, https://dblp.org}
24}1@software{chintala_torchvision_2017,
2author = {Chintala, Soumith},
3month = {4},
4title = {{Torchvision}},
5url = {https://github.com/pytorch/vision},
6year = {2017}
7}