Views
No views yet
pip install pylocronconda install -c frgfm pylocron1git clone https://github.com/frgfm/Holocron.git
2pip install -e Holocron/.1from PIL import Image
2from torchvision.transforms import Compose, ConvertImageDtype, Normalize, PILToTensor, Resize
3from torchvision.transforms.functional import InterpolationMode
4from holocron.models import model_from_hf_hub
5
6model = model_from_hf_hub("frgfm/cspdarknet53").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-1911-11929,
2 author = {Chien{-}Yao Wang and
3 Hong{-}Yuan Mark Liao and
4 I{-}Hau Yeh and
5 Yueh{-}Hua Wu and
6 Ping{-}Yang Chen and
7 Jun{-}Wei Hsieh},
8 title = {CSPNet: {A} New Backbone that can Enhance Learning Capability of {CNN}},
9 journal = {CoRR},
10 volume = {abs/1911.11929},
11 year = {2019},
12 url = {http://arxiv.org/abs/1911.11929},
13 eprinttype = {arXiv},
14 eprint = {1911.11929},
15 timestamp = {Tue, 03 Dec 2019 20:41:07 +0100},
16 biburl = {https://dblp.org/rec/journals/corr/abs-1911-11929.bib},
17 bibsource = {dblp computer science bibliography, https://dblp.org}
18}1@software{Fernandez_Holocron_2020,
2author = {Fernandez, François-Guillaume},
3month = {5},
4title = {{Holocron}},
5url = {https://github.com/frgfm/Holocron},
6year = {2020}
7}