wgpubs
(WG)
1
Was hoping that it would work in the same way as for image classification … but using an existing learner, the final one, I do …
test_img = open_image('../../tmp-projects/data/482.jpg')
learn.predict(test_img)
and I get the following exception because there is no y
to transform …
Is there a way in the data block API to do a single_from_classes
so we can get a DataBunch
with a modified transforms where tfm_y=False
?
wgpubs
(WG)
2
SOLVED:
It’s longwinded, but it works. Any recommendations on how to improve are welcome …
test_img = open_image(path_img/'0006R0_f02880.png')
train_tfms, val_tfms = get_transforms()
img = apply_tfms(val_tfms, test_img, size=size)
img_data= normalize(img.data, *list(map(tensor, imagenet_stats)))
data2 = ImageDataBunch.single_from_classes(path/'images', classes=codes, tfms=get_transforms(), size=size, bs=1).normalize(imagenet_stats)
learn2 = Learner.create_unet(data2, models.resnet34, pretrained=False)
learn2 = learn2.load('stage-2-big')
learn2.model.eval()
probs_msk = learn2.model(img_data.cuda().unsqueeze(0))
pred_msk = probs_msk.argmax(dim=1)
pred_msk.shape
pred_img_segment = ImageSegment(pred_msk)
fig, ax = plt.subplots(figsize=(10,10))
img.show(figsize=(10,10),ax=ax)
pred_img_segment.show(figsize=(10,10), alpha=.7, ax=ax)
5 Likes
Michal_w
(Michal Wawrzyniuk)
3
Hi,
So far is only one method to make prediction on single image for CAMVID
is there anyway we can use it wit learner.predict()
Thanks:)
Michal