Learners to train models.
/home/user/jupyter/env/lib/python3.7/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0

Splitters

Splitters for spliting the model into head and body for freezing and differential learning rates.

no_split[source]

no_split(m)

No split of params for models

rcnn_split[source]

rcnn_split(m)

Default split of params for fasterrcnn/maskrcnn models

effdet_split[source]

effdet_split(m)

Default split of params for efficientdet models

class ObjDetLearner[source]

ObjDetLearner(dls, model, loss_func=None, opt_func=Adam, lr=0.001, splitter=trainable_params, cbs=None, metrics=None, path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True, moms=(0.95, 0.85, 0.95)) :: Learner

Group together a model, some dls and a loss_func to handle training

ObjDetLearner.get_preds[source]

ObjDetLearner.get_preds(x:ObjDetLearner, items=None, item_tfms=None, batch_tfms=None, box_score_thresh=0.05, max_n=None, progress=True)

Get predictions of an ObjDetLearner. Set items to a list of PIL images, optionally with item and batch transforms. Returns denormalized inputs, bounding boxes, labels and scores as lists of tensors.

ObjDetLearner.show_results[source]

ObjDetLearner.show_results(x:ObjDetLearner, items=None, item_tfms=None, batch_tfms=None, box_score_thresh=0.5, max_n=5, progress=False)

Show results of a trained ObjDetLearner. If no items are specified, it uses images from the validation dataloader.

class InstSegLearner[source]

InstSegLearner(dls, model, loss_func=None, opt_func=Adam, lr=0.001, splitter=trainable_params, cbs=None, metrics=None, path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True, moms=(0.95, 0.85, 0.95)) :: Learner

Group together a model, some dls and a loss_func to handle training

InstSegLearner.get_preds[source]

InstSegLearner.get_preds(x:InstSegLearner, items=None, item_tfms=None, batch_tfms=None, box_score_thresh=0.05, bin_mask_thresh=None, max_n=None, progress=True)

Get predictions of an InstSegLearner. Set items to a list of PIL images, optionally with item and batch transforms. Returns denormalized inputs, masks, bounding boxes, labels and scores as lists of tensors. By default it returns masks in [N,1,H,W] with activations. If you want binary masks in [N,H,W], set a value for bin_mask_thresh (N: number of objects).

InstSegLearner.show_results[source]

InstSegLearner.show_results(x:InstSegLearner, items=None, item_tfms=None, batch_tfms=None, box_score_thresh=0.5, bin_mask_thresh=0.5, max_n=5, progress=False)

Show results of a trained InstSegLearner. If no items are specified, it uses images from the validation dataloader.

class fasterrcnn_learner[source]

fasterrcnn_learner(dls, model, pretrained=True, pretrained_backbone=True, num_classes=None, loss_func=noop, opt_func=Adam, lr=0.001, splitter=None, cbs=None, metrics=None, path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True, moms=(0.95, 0.85, 0.95), trainable_layers=5, min_size=800, max_size=1333, image_mean=None, image_std=None, rpn_anchor_generator=None, rpn_head=None, rpn_pre_nms_top_n_train=2000, rpn_pre_nms_top_n_test=1000, rpn_post_nms_top_n_train=2000, rpn_post_nms_top_n_test=1000, rpn_nms_thresh=0.7, rpn_fg_iou_thresh=0.7, rpn_bg_iou_thresh=0.3, rpn_batch_size_per_image=256, rpn_positive_fraction=0.5, box_roi_pool=None, box_head=None, box_predictor=None, box_score_thresh=0.05, box_nms_thresh=0.5, box_detections_per_img=100, box_fg_iou_thresh=0.5, box_bg_iou_thresh=0.5, box_batch_size_per_image=512, box_positive_fraction=0.25, bbox_reg_weights=None) :: ObjDetLearner

fastai-style learner to train fasterrcnn models

Type Default Details
dls No Content
model No Content
pretrained bool True No Content
pretrained_backbone bool True No Content
num_classes NoneType `` No Content
loss_func function noop No Content
opt_func function Adam No Content
lr float 001 No Content
splitter NoneType `` No Content
cbs NoneType `` No Content
metrics NoneType `` No Content
path NoneType `` learner args
model_dir str models No Content
wd NoneType `` No Content
wd_bn_bias bool False No Content
train_bn bool True No Content
moms tuple 95) No Content
kwargs No Content

class maskrcnn_learner[source]

maskrcnn_learner(dls, model, pretrained=True, pretrained_backbone=True, num_classes=None, loss_func=noop, opt_func=Adam, lr=0.001, splitter=None, cbs=None, metrics=None, path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True, moms=(0.95, 0.85, 0.95), trainable_layers=5, min_size=800, max_size=1333, image_mean=None, image_std=None, rpn_anchor_generator=None, rpn_head=None, rpn_pre_nms_top_n_train=2000, rpn_pre_nms_top_n_test=1000, rpn_post_nms_top_n_train=2000, rpn_post_nms_top_n_test=1000, rpn_nms_thresh=0.7, rpn_fg_iou_thresh=0.7, rpn_bg_iou_thresh=0.3, rpn_batch_size_per_image=256, rpn_positive_fraction=0.5, box_roi_pool=None, box_head=None, box_predictor=None, box_score_thresh=0.05, box_nms_thresh=0.5, box_detections_per_img=100, box_fg_iou_thresh=0.5, box_bg_iou_thresh=0.5, box_batch_size_per_image=512, box_positive_fraction=0.25, bbox_reg_weights=None, mask_roi_pool=None, mask_head=None, mask_predictor=None) :: InstSegLearner

fastai-style learner to train maskrcnn models

Type Default Details
dls No Content
model No Content
pretrained bool True No Content
pretrained_backbone bool True No Content
num_classes NoneType `` No Content
loss_func function noop No Content
opt_func function Adam No Content
lr float 001 No Content
splitter NoneType `` No Content
cbs NoneType `` No Content
metrics NoneType `` No Content
path NoneType `` learner args
model_dir str models No Content
wd NoneType `` No Content
wd_bn_bias bool False No Content
train_bn bool True No Content
moms tuple 95) No Content
kwargs No Content

class efficientdet_learner[source]

efficientdet_learner(dls, model, pretrained=True, pretrained_backbone=True, num_classes=None, loss_func=noop, opt_func=Adam, lr=0.001, splitter=None, cbs=None, metrics=None, path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True, moms=(0.95, 0.85, 0.95), compound_coef=0, nms_score_thresh=0.05, nms_iou_thresh=0.5, focal_loss_alpha=0.25, focal_loss_gamma=2.0, ratios='[(1.0,1.0),(1.4,0.7),(0.7,1.4)]', scales='[2**0, 2**(1.0/3.0), 2**(2.0/3.0)]') :: ObjDetLearner

fastai-style learner to train efficientdet models

Type Default Details
dls No Content
model No Content
pretrained bool True No Content
pretrained_backbone bool True No Content
num_classes NoneType `` No Content
loss_func function noop No Content
opt_func function Adam No Content
lr float 001 No Content
splitter NoneType `` No Content
cbs NoneType `` No Content
metrics NoneType `` No Content
path NoneType `` learner args
model_dir str models No Content
wd NoneType `` No Content
wd_bn_bias bool False No Content
train_bn bool True No Content
moms tuple 95) No Content
kwargs No Content

Download dataset

from fastai_object_detection.dataloaders import ObjectDetectionDataLoaders
from fastai_object_detection.datasets import CocoData
path,df = CocoData.create("coco-person", cat_list=["person"], max_images=2000, with_mask=True)
df.head(2)
Creating folders.
Downloading annotation files...
loading annotations into memory...
Done (t=16.43s)
creating index...
index created!
Found 1 valid categories.
['person']
Starting download.
Downloading images of category person
2000 images downloaded.
Creating Dataframe...
100.00% [2000/2000 00:34<00:00]
image_id image_path mask_path object_id x_min y_min x_max y_max class_name
0 263355 /root/.fastai/data/coco-person/images/000000263355.jpg /root/.fastai/data/coco-person/masks/000000263355_0.png 0 269.99 132.22 343.71 223.17 person
1 263355 /root/.fastai/data/coco-person/images/000000263355.jpg /root/.fastai/data/coco-person/masks/000000263355_1.png 1 309.00 202.10 397.00 313.10 person

Example Object Detection

df_bb_only = df.drop(columns=["mask_path"])
dls = ObjectDetectionDataLoaders.from_df(df_bb_only, valid_pct=0.1, bs=4, 
                                        item_tfms=[Resize(512, method='pad', pad_mode='zeros')],
                                        batch_tfms=[Normalize.from_stats(*imagenet_stats)])
dls.show_batch(figsize=(10,10))
sgd_90 = partial(SGD, mom=0.9)
learn = efficientdet_learner(dls, efficientdet_d0, 
                             opt_func=sgd_90, lr=0.005, wd=0.0005, train_bn=False,
                             metrics=[mAP_at_IoU50])
learn.freeze()
Downloading: "https://github.com/zylo117/Yet-Another-Efficient-Pytorch/releases/download/1.0/efficientdet-d0.pth" to /root/.cache/torch/hub/checkpoints/efficientdet-d0.pth

learn.lr_find()
SuggestedLRs(valley=0.0002290867705596611)
learn.fit_one_cycle(5, 2.3e-04)
epoch train_loss valid_loss mAP@IoU>0.5 time
0 2.305032 2.408169 0.548403 01:43
1 2.000504 2.264517 0.644334 01:43
2 1.984223 2.031550 0.655357 01:42
3 1.917781 1.986832 0.672677 01:43
4 1.869135 1.993827 0.670611 01:42
learn.show_results(max_n=5)
img = PILImage.create("/root/.fastai/data/coco-person/images/000000263355.jpg")
img
learn.get_preds(items=[img],     
                item_tfms=[Resize(512, method="pad", pad_mode="zeros")], 
                batch_tfms=[Normalize.from_stats(*imagenet_stats)]
                )
100.00% [1/1 00:00<00:00]
([TensorImage([[[0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           ...,
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0]],
  
          [[0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           ...,
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0]],
  
          [[0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           ...,
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0]]])],
 [TensorImage([[314.8459, 302.2313, 371.7278, 368.9285],
          [251.9834, 243.4367, 315.5932, 321.2910],
          [217.6628, 192.4591, 272.4676, 267.0927],
          [ 67.1360, 139.5841, 109.5052, 203.0207],
          [229.3078, 191.4265, 286.0752, 298.0247],
          [ 73.2442, 155.6000,  98.1103, 199.7644],
          [247.3950, 223.7528, 310.7683, 293.9751],
          [331.5434, 323.7770, 349.8584, 358.7201],
          [235.0905, 209.4596, 268.9167, 265.7909],
          [ 57.6022, 124.4398, 117.7872, 216.8158],
          [266.9063, 259.4075, 302.7794, 318.3243],
          [242.2965, 193.5674, 273.0590, 247.1761],
          [273.7638, 280.3947, 341.0608, 345.1314],
          [ 80.9486, 141.3708, 113.3200, 182.9938],
          [270.2173, 251.4402, 348.0386, 371.0154],
          [338.2918, 319.6792, 359.7049, 359.2232],
          [ 67.1544, 175.3793,  99.3211, 206.4258],
          [270.5588, 254.4981, 328.1692, 329.2501],
          [333.9679, 303.5755, 371.6255, 353.9009],
          [187.2097, 181.9707, 258.4285, 286.0948],
          [287.0978, 296.4323, 358.0831, 364.5014],
          [ 76.4600, 166.9778, 105.6066, 206.5264],
          [ 63.8489, 162.3354,  91.4579, 198.9496],
          [321.6934, 306.1715, 361.5071, 346.1221],
          [235.5691, 218.0357, 252.3576, 251.9187],
          [299.5428, 331.8849, 366.4805, 372.2044],
          [241.9729, 197.7260, 301.5856, 263.3047],
          [233.9926, 178.7457, 311.4689, 321.9977],
          [214.7897, 238.9272, 286.4854, 309.9632],
          [280.0527, 319.8374, 393.3344, 381.0396],
          [228.9199, 216.4604, 261.4066, 252.4969],
          [ 69.2948, 141.2676, 103.7377, 178.4376],
          [226.7171, 241.4281, 260.8327, 269.6660],
          [208.1756, 182.5988, 268.8554, 242.7404],
          [ 59.7241, 158.2499,  99.8671, 209.7462],
          [220.5194, 269.3233, 335.2883, 339.2118],
          [340.8872, 334.1149, 357.0036, 363.3123],
          [240.7481, 302.5533, 305.3769, 334.4046],
          [ 55.7457, 181.9400, 105.2003, 210.5162],
          [281.1266, 237.1904, 330.2955, 300.3294],
          [205.8860, 236.4177, 269.8257, 271.4654],
          [317.0248, 326.9958, 347.7203, 364.1012],
          [215.4411, 220.9789, 295.4763, 269.4453],
          [295.4563, 262.3488, 354.3756, 336.4473],
          [195.6868, 203.4846, 307.7991, 281.7633],
          [ 73.2637, 136.7948, 137.4286, 201.6188],
          [229.2888, 195.6577, 264.1551, 229.8488],
          [232.0498, 177.0077, 284.6206, 238.1906],
          [243.8462, 231.8220, 342.6601, 333.6975],
          [318.4372, 344.1028, 357.8311, 372.4455],
          [185.9786, 216.1969, 245.5412, 274.9942],
          [272.2248, 274.0951, 301.0020, 310.3282],
          [326.3359, 327.9253, 358.7753, 349.0920],
          [255.0938, 288.9568, 324.2076, 354.1015],
          [335.4579, 338.5995, 362.1481, 358.8314],
          [ 80.4007, 139.9671, 108.1043, 159.6084],
          [ 72.8994, 172.9708,  93.3892, 191.3519],
          [ 57.0965, 178.3524,  87.6162, 205.6226],
          [286.7004, 248.3407, 314.4547, 281.1805],
          [ 50.4148, 168.7152,  90.8454, 215.4422],
          [333.6432, 302.6187, 369.0951, 330.3940],
          [272.2386, 260.5270, 299.9893, 295.2851],
          [315.2869, 264.0927, 372.5961, 344.3143],
          [278.4494, 284.0971, 396.7112, 367.2631],
          [347.5180, 305.0301, 372.6911, 335.7895],
          [270.7090, 250.7806, 315.5233, 298.8588],
          [201.5378, 211.7221, 267.4250, 258.1007],
          [242.9493, 210.5844, 262.7848, 245.2156],
          [304.2919, 349.3525, 374.0923, 377.1111],
          [222.8735, 225.7419, 250.7053, 258.8065],
          [214.7186, 166.3976, 295.2955, 261.7578],
          [ 70.3981, 136.7816,  99.5539, 159.8159],
          [ 40.2870, 119.5665, 151.3493, 201.7758],
          [178.8432, 186.9214, 235.1214, 250.8099],
          [259.9396, 273.1387, 291.6614, 310.1445],
          [170.2593, 163.7362, 236.0851, 283.4980],
          [ 80.1291, 181.7332, 107.0672, 211.1929],
          [241.6538, 285.2744, 305.3462, 327.2621],
          [252.7699, 193.5732, 273.4632, 232.5597],
          [236.3424, 190.2546, 270.3062, 223.0407],
          [338.4277, 329.8690, 371.7092, 350.4366],
          [210.3917, 246.6646, 255.7498, 273.0786],
          [ 74.6990, 166.5801, 102.5500, 189.7267],
          [336.3510, 343.6072, 370.3357, 374.0395],
          [274.6082, 245.1078, 310.5720, 275.4107],
          [248.8191, 296.2688, 281.6764, 321.5770],
          [291.3505, 235.8604, 318.8208, 294.1190],
          [ 27.4121, 159.9925, 147.2399, 228.1742],
          [ 69.0428, 159.8928,  98.1283, 181.8794],
          [277.8496, 266.7154, 307.6522, 304.2852],
          [261.8126, 259.8317, 290.3650, 292.3976]])],
 [TensorImage([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
          1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
          1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
          1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
          1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
          1.])],
 [TensorImage([0.8067, 0.6761, 0.6234, 0.5469, 0.3665, 0.2612, 0.2322, 0.2162, 0.2023,
          0.2006, 0.1968, 0.1774, 0.1741, 0.1720, 0.1695, 0.1636, 0.1583, 0.1503,
          0.1493, 0.1492, 0.1485, 0.1427, 0.1397, 0.1356, 0.1325, 0.1301, 0.1283,
          0.1214, 0.1202, 0.1192, 0.1164, 0.1141, 0.1140, 0.1115, 0.1084, 0.1039,
          0.1029, 0.1017, 0.1006, 0.0981, 0.0978, 0.0934, 0.0911, 0.0906, 0.0902,
          0.0901, 0.0898, 0.0895, 0.0844, 0.0819, 0.0812, 0.0806, 0.0794, 0.0794,
          0.0787, 0.0781, 0.0779, 0.0768, 0.0754, 0.0753, 0.0742, 0.0711, 0.0705,
          0.0698, 0.0676, 0.0674, 0.0667, 0.0662, 0.0655, 0.0643, 0.0642, 0.0613,
          0.0601, 0.0601, 0.0599, 0.0597, 0.0592, 0.0588, 0.0584, 0.0578, 0.0575,
          0.0570, 0.0569, 0.0556, 0.0550, 0.0537, 0.0526, 0.0524, 0.0512, 0.0510,
          0.0502])])
learn.show_results(items=[img],     
                   item_tfms=[Resize(512, method="pad", pad_mode="zeros")], 
                   batch_tfms=[Normalize.from_stats(*imagenet_stats)]
                )

Example Instance Segmentation

dls = ObjectDetectionDataLoaders.from_df(df, valid_pct=0.1, bs=2, 
                                        item_tfms=[Resize(800, method='pad', pad_mode='zeros')],
                                        batch_tfms=[Normalize.from_stats(*imagenet_stats)])
dls.show_batch(figsize=(10,10))
/usr/local/lib/python3.7/dist-packages/fastai_object_detection/core.py:24: UserWarning: No contour levels were found within the data range.
  ax.contour(m, colors=[color_mask[0, 0, :]], alpha=0.4)
learn = maskrcnn_learner(dls, maskrcnn_resnet50, 
                         opt_func=sgd_90, lr=0.005, wd=0.0005, train_bn=False,
                         metrics=[mAP_at_IoU50])
learn.freeze()
learn.lr_find()
SuggestedLRs(valley=0.0008317637839354575)
learn.fit_one_cycle(3, 8.3e-04)
epoch train_loss valid_loss mAP@IoU>0.5 time
0 0.575378 0.614994 0.867840 05:04
1 0.527363 0.604820 0.877205 05:03
2 0.521993 0.593871 0.879088 05:03
learn.show_results(max_n=1)
inp, mask, bbox, labels, scores = learn.get_preds(max_n=1, bin_mask_thresh=0.5, progress=False)
inp[0].shape,mask[0].shape,bbox[0].shape,labels[0].shape,scores[0].shape
(torch.Size([3, 800, 800]),
 torch.Size([24, 800, 800]),
 torch.Size([24, 4]),
 torch.Size([24]),
 torch.Size([24]))
learn.get_preds(items=[img],     
                item_tfms=[Resize(800, method="pad", pad_mode="zeros")], 
                batch_tfms=[Normalize.from_stats(*imagenet_stats)]
                )
100.00% [1/1 00:01<00:00]
([TensorImage([[[0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           ...,
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0]],
  
          [[0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           ...,
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0]],
  
          [[0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           ...,
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0],
           [0, 0, 0,  ..., 0, 0, 0]]])],
 [tensor([[[[0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            ...,
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.]]],
  
  
          [[[0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            ...,
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.]]],
  
  
          [[[0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            ...,
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.]]],
  
  
          ...,
  
  
          [[[0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            ...,
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.]]],
  
  
          [[[0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            ...,
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.]]],
  
  
          [[[0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            ...,
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.],
            [0., 0., 0.,  ..., 0., 0., 0.]]]])],
 [tensor([[338.1653, 300.1348, 426.5469, 410.1504],
          [102.6981, 222.3431, 172.7082, 311.6075],
          [485.7284, 476.4229, 582.6495, 563.8487],
          [397.0197, 389.0280, 493.7053, 494.6345],
          [124.3245, 221.1269, 172.6624, 287.4283],
          [104.4376, 276.8195, 150.5649, 322.6822],
          [ 98.1711, 254.7122, 155.6501, 317.4437],
          [372.5593, 377.3335, 504.7784, 536.2596],
          [481.9142, 496.8055, 552.8765, 577.4226]])],
 [tensor([1, 1, 1, 1, 1, 1, 1, 1, 1])],
 [tensor([0.9966, 0.9953, 0.9951, 0.9930, 0.1394, 0.1326, 0.1204, 0.0598, 0.0514])])
learn.show_results(items=[img],     
                   item_tfms=[Resize(512, method="pad", pad_mode="zeros")], 
                   batch_tfms=[Normalize.from_stats(*imagenet_stats)]
                )