April 2020
Intermediate to advanced
438 pages
12h 2m
English
Go through the following steps to classify an image using pretrained deep neural net models with PyTorch/torchvision:
def classify(img, model_index, model_name, model_pred, labels): _, index = torch.max(model_pred, 1) model_pred, indices = torch.sort(model_pred, dim=1,\ descending=True) percentage = torch.nn.functional.softmax(model_pred, dim=1)\ [0] * 100 draw = ImageDraw.Draw(img) font = ImageFont.truetype(r'arial.ttf', 50) draw.text((5, 5+model_index*50),'{}, pred: \ {},{}%'.format(model_name, ...Read now
Unlock full access