After taking lesson 1, I tried out image classification with stanford cars dataset.
I was having trouble with using the test set in ImageDataBunch. This is how my ImageDataBunch looks now.
data = ImageDataBunch.from_df(path/'car_ims', train_df, ds_tfms=get_transforms(), size=224, bs=bs).normalize(imagenet_stats)
test_data = ImageList.from_df(test_df, path/'car_ims')
data.add_test(test_data)
ImageDataBunch;
Train: LabelList (6516 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: CategoryList
AM General Hummer SUV 2000,AM General Hummer SUV 2000,AM General Hummer SUV 2000,AM General Hummer SUV 2000,AM General Hummer SUV 2000
Path: /home/jupyter/.fastai/data/stanford-cars/car_ims;
Valid: LabelList (1628 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: CategoryList
Chevrolet Avalanche Crew Cab 2012,Ford F-150 Regular Cab 2007,Audi TT Hatchback 2011,Ferrari 458 Italia Convertible 2012,MINI Cooper Roadster Convertible 2012
Path: /home/jupyter/.fastai/data/stanford-cars/car_ims;
Test: LabelList (8041 items)
x: ImageList
Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224),Image (3, 224, 224)
y: EmptyLabelList
,,,,
Path: /home/jupyter/.fastai/data/stanford-cars/car_ims
After training the model, in order to get the test predictions I used the following code, but I wanted to know if there is a way to predict labels for all images in the test set without iteration.
test_predictions = []
for test_image in test_data:
test_predictions.append(learn.predict(test_image)[0])
This gave the label for each image in the testset.
Is there a more straightforward way to achieve this?