I had submitted this post and got no feedback so I added color to the B&W images in a small subset of the training images and found that I now get 0.000000 train_loss, valid_loss and error_rate. My code is as shown below with the B&W centric code commented out and the additional code for color below those comments.
the shape of pix is: (224, 224, 3) image format: PNG image size: (224, 224) image mode: RGB
I train using the following code:
from fastai.vision.all import * if __name__ == '__main__': path = 'C:/training' #the following line was added because of Microsoft Windows and computer num_workers=0 silence = DataBlock( #blocks=(ImageBlock(cls=PILImageBW), CategoryBlock), blocks=(ImageBlock, CategoryBlock), get_items=get_image_files, splitter=RandomSplitter(valid_pct=0.2, seed=42), get_y=parent_label, item_tfms=Resize(224, ResizeMethod.Pad, pad_mode='zeros')) dls = silence.dataloaders(path) learn = cnn_learner(dls, resnet18, model_dir='C:/models/', #metrics=error_rate, loss_func=BCEWithLogitsLossFlat()) metrics=error_rate) learn.fine_tune(1) dls.valid.show_batch(max_n=4, nrows=1) learn.export()
When I used the model trained with the B&W images for “silence” I got the following result:
pred is:  , pred_idx is: tensor([False]) and probs is: tensor([0.0536])
When I used the model trained with the color images for “silence” I now get the following result:
pred is: silence , pred_idx is: tensor(0) and probs is: tensor([1.])
Now, the prediction is not empty. However when I test a noisy sample, both B&W and colorized, the result is the same as that for the “silent” image shown above. Also, when I run:
pred,pred_idx,probs = learn_inf.predict('C:/HOME/.fastai/data/oxford-iiit-pet/images/Abyssinian_1.jpg')
I also get
pred is: silence , pred_idx is: tensor(0) and probs is: tensor([1.]), which should not happen as it’s a cat.
What might be going wrong?
How can I get logs of what fastai is doing for troubleshooting?
The fastai lesson samples work using essentially the same process shown here.