Can I do lesson 2 on real time system?

I think you can get it work with an IDE. Might require some fiddling.

I tried it on terminal and againt its nothing to show. Actually ı dont need to show it ı have to predict it .I changed line of im.show() to learn.predict(im) and I get this error : RuntimeError: expected type torch.cuda.FloatTensor but got torch.cuda.ByteTensor
Have to I change parameters or is im the wrong parameter to send to learn.predict .

Can you send the example image your trying

Try np.float32 instead of np.uint8

It worked but it find wrong class i think i have to retrain my model .

You verify that the image is being imported correctly using im.show()

I tried it but im.show() isn’t show anything

Try saving the image

Also try with show_image(im)

This works for me.

import cv2

model_path = Path('/models/model02')
learn = load_learner(model_path)

vidcap = cv2.VideoCapture(0)

while True:    
    ret, frame = vidcap.read()
    pred_class = learn.predict(Image(pil2tensor(frame, np.float32).div_(255)))[0]    
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

vidcap.release()
cv2.destroyAllWindows()
2 Likes

it works but same problem for me . My model predicting wrong class actually it always predicting one of classes. Is it overfitting problem ? How can ı predict my ımage classifier model correctly?

Hi, @hamdikaptan1 I’m facing the same problem.
I tried the same way in your code. Neither im.show() nor show_image(im) displayed the image. The output was just white and the prediction was also wrong, though my model had 96% accuracy.
How did you overcome this problem?

I tried restart training model with new dataset. Applied data augmentation on my data .My model had 96% acc. but ı think it was overfitting problem.

@hamdikaptan1
Oh ,ok. If you get the right predictions please share it.

Hi,

When I’m running the block I’m getting an error at :
im = Image(t)
TypeError: ‘module’ object is not callable

1 Like

Same problem man. Have you managed to fix this problem?

Try im = Image.Image(t)

1 Like

Thanks!