Applied Machine Learning for Health and Fitness by Kevin Ashley

Applied Machine Learning for Health and Fitness by Kevin Ashley

Author:Kevin Ashley
Language: eng
Format: epub
ISBN: 9781484257722
Publisher: Apress


Thanks to torchvision, if we don’t have the model, it gets downloaded automatically into .cache:Downloading: "https://download.pytorch.org/models/fasterrcnn_resnet50_fpn_coco-258fb6c6.pth" to .cache\torch\checkpoints\fasterrcnn_resnet50_fpn_coco-258fb6c6.pth

100.0%

Next, I created filter_detections method that runs predictions, based on our model, and filters predictions using a threshold of 0.7 confidence (we are not interested in surfboards with confidence level less than 70%)!def filter_detections(img, model, threshold=.7):

with torch.no_grad():

img_t = T.ToTensor()(img)

img_t = img_t.unsqueeze(0)

if next(model.parameters()).is_cuda:

img_t = img_t.pin_memory().cuda(non_blocking=True)

pred = model(img_t)[0]

boxes = pred['boxes']

box_scores = pred['scores']

labels = pred['labels']

idxs = [i for (i,s) in enumerate(box_scores) if s > threshold]

res = [(COCO_CLASSES[labels[i].cpu().tolist()],boxes[i].cpu().numpy()) for i in idxs]

return res



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.