Computer Vision News - February 2020
2 Summary We Tried for You 14 We implemented for you a classification task and used pretrained model of Efficient-Net. PyTorch offers an implementation of this scheme of networks as well as the baseline methods that Efficient-Net tries to improve. We would like to test whether the number of FLOPs is a good measure for the running time of the algorithm. Below is the implementation of our experiment: Implementation import json from PIL import Image import torch from torchvision import transforms import torchvision.models as models import time from efficientnet_pytorch import EfficientNet Image_Name = 'panda.jpg' model = EfficientNet . from_pretrained( 'efficientnet-b1' ) img = Image . open(Image_Name) labels_map = json . load( open ( 'label.txt' )) labels_map = [labels_map[ str (i)] for i in range ( 1000 )] image_size = img . size tfms = transforms . Compose([transforms . Resize(image_size), transforms . CenterCrop(image_size), transforms . ToTensor(), transforms . Normalize([ 0.485 , 0.456 , 0.406 ], [ 0.229 , 0.224 , 0.225 ]),]) img = tfms(img) . unsqueeze( 0 ) total_time = - time . time() model . eval() with torch . no_grad(): logits = model(img) total_time += time . time() print ( 'Total Time EfficientNet:' ,total_time) preds = torch . topk(logits, k = 5 ) . indices . squeeze( 0 ) . tolist() for idx in preds: label = labels_map[idx] prob = torch . softmax(logits, dim = 1 )[ 0 , idx] . item() print ( '{:<75} ({:.2f}%)' . format(label, prob * 100 ))
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=