I have been trying to get single image classification to work on the dogs/cats example from lesson 1, but passing in the images from the validation set is yielding some unexpected results. I have the following code:
I can see from the data.classes variable that a 0 indicates a cat and a 1 indicates a dog, but the values in the preds array are almost half and half 1’s and 0’s.
Shouldn’t the values in the preds array be almost entirely 0’s (cats) since these images are from the cats portion of the validation set (aka, the set that the training process used to determine that the model has ~99% accuracy). OR perhaps I have a bug in my code or a fundamental misunderstanding of how the training process works / how the validation set is used. Can anyone set me straight?
I’m trying to predict a single image and have gotten the code to run without any errors; however, I’m not exactly sure what the “np.argmax(preds)” is supposed to output. I added the print(preds[:2]) to see what preds was actually equal to. If the “np.argmax(preds)” outputs which type of image it thinks it is which is what I thought it did then it seems to get most of them wrong. There are also dramatic swings in what the preds is equal to when you retrain the model. Could someone try to explain this to me? Thanks. Here is the code.
I am doing it like above, but if I have to take my saved model to someplace else and make predictions out of it, do I need to take the training data with it too ? as I understand from
Quick question regarding this approach - how are you making sure that the models from pytorch and fast ai have the excact same architecture? I tried this approach using Resnet18 but got a mismatch of names when trying to load the weights from fast ai in raw pytorch
If one needs to load the model architecture from learn.models.model it is still dependent on fast ai
Has anyone got a working example how to load a fastai model into pytorch, to use it for prediction? I would like to be able to train my model in fastai, but then just load it with pytorch for prediction without having to install fastai.
How can apply that object detection model [lesson (9)] on new image data set?
I tried
fp = str(PATH) + “/” + “person.jpg” ; fp
trn_tfms, val_tfms = tfms_from_model(f_model, sz, aug_tfms=transforms_side_on, max_zoom=1.05) # get transformations
im = val_tfms(open_image(fp))
learn.precompute=False
preds = learn.predict_array(im[None])
but I got array! and the shape of array are : print(im[None].shape) , print(im.shape)
(1, 3, 224, 224)
(3, 224, 224)
Is there any suggestion?