I have followed the tutorial from Lesson 1, and then created a new (simple) dataset with watches and basketballs (dumb, I know, but just wanted to learn the process). After working through a few issues, mainly bad images, I have a model. Now, I want to test a new image against that model, but can’t figure it out.
I have a new notebook with the following:
from fastai.imports import *
from fastai import *
from fastai.vision import *
from fastai.metrics import error_rate
PATH = “/home/ubuntu/course-v3/nbs/dl1/datasets/basketball_watches”
sz=224
arch=models.resnet34
data = ImageDataBunch.from_folder(PATH, size=sz, test_name=‘test’, ds_tfms=get_transforms())
When I run the cell, I get:
/home/ubuntu/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_data.py:226: UserWarning: There seems to be something wrong with your dataset, can’t access any element of self.train_ds.
Tried: 86,114,77,70,110…
warn(warn_msg)
I have also tried an example I found in the docs:
empty_data = ImageDataBunch.load_empty(PATH)
learn = create_cnn(empty_data, models.resnet34)
learn = learn.load(‘ball-watch-stage-1’)
but receive TypeError: unsupported operand type(s) for /: ‘str’ and ‘str’
I am sure this is simple, but I can’t figure it out. Any help is appreciated.
/home/ubuntu/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_data.py:226: UserWarning: There seems to be something wrong with your dataset, can’t access any element of self.train_ds.
Tried: 53,103,121,13,58…
warn(warn_msg)
I printed out PATH and see that the format you suggested does change it from ‘/home/ubuntu/course-v3/nbs/dl1/datasets/basketball_watches’ to PosixPath(’/home/ubuntu/course-v3/nbs/dl1/datasets/basketball_watches’)
I also used the googimagesearch package to create a custom data set. My high-level steps are below:
Download images
rename images (I wrote a python script to do this)
delete images that don’t show up with a thumbnail in Finder (not sure why, but some images are like this and break the training process)
Organize the images into the expected format (data_set/test, train, valid - with subfolders for each class (e.g. rats, basketballs, squirrels, dogs, watches)
Train the model
Save
In new notebook, set the path=Path("/home/ubuntu/course-v3/nbs/dl1/data_set/")
Define the classes = ['basketballs",“dogs”…]
create a databunch --> data = ImageDateBunch.single_from_classes(path, classes, tfms=get_transformations(), size=224).normalize(imagenet_stats)
learn = create_cnn(data, models.resnet34)
load the saved model (?) --> learn.load('file you saved in step 6")
I was not able to import an image of my dog to compare it to the model. I am using Google colab and every time I change the code around I get another weird error.