diff --git a/pytorch_vision_alexnet.md b/pytorch_vision_alexnet.md index 8a6979e6..bae4c168 100644 --- a/pytorch_vision_alexnet.md +++ b/pytorch_vision_alexnet.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_densenet.md b/pytorch_vision_densenet.md index b33a7ba7..641a0abd 100644 --- a/pytorch_vision_densenet.md +++ b/pytorch_vision_densenet.md @@ -65,9 +65,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_ghostnet.md b/pytorch_vision_ghostnet.md index 33a4accb..233c5c8e 100644 --- a/pytorch_vision_ghostnet.md +++ b/pytorch_vision_ghostnet.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_googlenet.md b/pytorch_vision_googlenet.md index 660c82d8..3136e227 100644 --- a/pytorch_vision_googlenet.md +++ b/pytorch_vision_googlenet.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_hardnet.md b/pytorch_vision_hardnet.md index 3a9234f0..34f8663e 100644 --- a/pytorch_vision_hardnet.md +++ b/pytorch_vision_hardnet.md @@ -65,9 +65,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_ibnnet.md b/pytorch_vision_ibnnet.md index 98dcfdf9..3b0e5d40 100644 --- a/pytorch_vision_ibnnet.md +++ b/pytorch_vision_ibnnet.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_inception_v3.md b/pytorch_vision_inception_v3.md index 19a2f556..c79a2aec 100644 --- a/pytorch_vision_inception_v3.md +++ b/pytorch_vision_inception_v3.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_meal_v2.md b/pytorch_vision_meal_v2.md index c3540aaf..6989bf6d 100644 --- a/pytorch_vision_meal_v2.md +++ b/pytorch_vision_meal_v2.md @@ -16,6 +16,12 @@ accelerator: cuda order: 10 --- +We require one additional Python dependency + +```bash +!pip install timm +``` + ```python import torch # list of models: 'mealv1_resnest50', 'mealv2_resnest50', 'mealv2_resnest50_cutmix', 'mealv2_resnest50_380x380', 'mealv2_mobilenetv3_small_075', 'mealv2_mobilenetv3_small_100', 'mealv2_mobilenet_v3_large_100', 'mealv2_efficientnet_b0' @@ -63,9 +69,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description @@ -86,13 +107,13 @@ In this paper, we introduce a simple yet effective approach that can boost the v ### References -Please refer to our papers [MEAL V2](https://arxiv.org/pdf/2009.08453.pdf), [MEAL](https://arxiv.org/pdf/1812.02425.pdf) for more details. - - @article{shen2020mealv2, - title={MEAL V2: Boosting Vanilla ResNet-50 to 80%+ Top-1 Accuracy on ImageNet without Tricks}, - author={Shen, Zhiqiang and Savvides, Marios}, - journal={arXiv preprint arXiv:2009.08453}, - year={2020} +Please refer to our papers [MEAL V2](https://arxiv.org/pdf/2009.08453.pdf), [MEAL](https://arxiv.org/pdf/1812.02425.pdf) for more details. + + @article{shen2020mealv2, + title={MEAL V2: Boosting Vanilla ResNet-50 to 80%+ Top-1 Accuracy on ImageNet without Tricks}, + author={Shen, Zhiqiang and Savvides, Marios}, + journal={arXiv preprint arXiv:2009.08453}, + year={2020} } @inproceedings{shen2019MEAL, @@ -100,4 +121,4 @@ Please refer to our papers [MEAL V2](https://arxiv.org/pdf/2009.08453.pdf), [MEA author = {Shen, Zhiqiang and He, Zhankui and Xue, Xiangyang}, booktitle = {AAAI}, year = {2019} - } \ No newline at end of file + } diff --git a/pytorch_vision_mobilenet_v2.md b/pytorch_vision_mobilenet_v2.md index a7baa5cf..c81382a4 100644 --- a/pytorch_vision_mobilenet_v2.md +++ b/pytorch_vision_mobilenet_v2.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_proxylessnas.md b/pytorch_vision_proxylessnas.md index 235fa965..9570b18e 100644 --- a/pytorch_vision_proxylessnas.md +++ b/pytorch_vision_proxylessnas.md @@ -63,9 +63,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_resnest.md b/pytorch_vision_resnest.md index c90b344c..9801bb50 100644 --- a/pytorch_vision_resnest.md +++ b/pytorch_vision_resnest.md @@ -64,9 +64,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_resnet.md b/pytorch_vision_resnet.md index f3d1d14a..0ce5a3e4 100644 --- a/pytorch_vision_resnet.md +++ b/pytorch_vision_resnet.md @@ -66,9 +66,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_shufflenet_v2.md b/pytorch_vision_shufflenet_v2.md index 13818f11..572ed1ea 100644 --- a/pytorch_vision_shufflenet_v2.md +++ b/pytorch_vision_shufflenet_v2.md @@ -61,9 +61,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_squeezenet.md b/pytorch_vision_squeezenet.md index f494ee11..423a2295 100644 --- a/pytorch_vision_squeezenet.md +++ b/pytorch_vision_squeezenet.md @@ -63,9 +63,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_vgg.md b/pytorch_vision_vgg.md index 1749cb14..35859875 100644 --- a/pytorch_vision_vgg.md +++ b/pytorch_vision_vgg.md @@ -69,9 +69,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description diff --git a/pytorch_vision_wide_resnet.md b/pytorch_vision_wide_resnet.md index e09ba008..4f734bda 100644 --- a/pytorch_vision_wide_resnet.md +++ b/pytorch_vision_wide_resnet.md @@ -64,9 +64,24 @@ with torch.no_grad(): # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes print(output[0]) # The output has unnormalized scores. To get probabilities, you can run a softmax on it. -print(torch.nn.functional.softmax(output[0], dim=0)) +probabilities = torch.nn.functional.softmax(output[0], dim=0) +print(probabilities) +``` ``` +# Download ImageNet labels +!wget https://github.com/raw/pytorch/hub/master/imagenet_classes.txt +``` + +``` +# Read the categories +with open("imagenet_classes.txt", "r") as f: + categories = [s.strip() for s in f.readlines()] +# Show top categories per image +top5_prob, top5_catid = torch.topk(probabilities, 5) +for i in range(top5_prob.size(0)): + print(categories[top5_catid[i]], top5_prob[i].item()) +``` ### Model Description