I am trying to figure out why I would be getting two different outputs for the same image(s) between using ImageDataBunch.from_folder
and ImageDataBunch.single_from_classes
using the same trained model. I am hoping someone can shed some light into this. I was using the ImageDataBunch.single_from_classes
for use with Render.com but am getting totally wrong outputs (not so when using ImageDataBunch.from_folder
)
I have double checked the folder and classes list and they all match.
Using ImageDataBunch.from_folder code
: Get the right output
import fastai
from fastai.vision import *
from fastai.widgets import *
from fastai.callbacks import *
from fastai.metrics import accuracy_thresh, top_k_accuracy, error_rate, FBeta, root_mean_squared_error, mean_squared_error, mean_absolute_error
path = Path('./data/0418_Combined')
tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=0.77, max_zoom=1.07,
max_lighting=0.2, max_warp=0.2, p_affine=0.2,
p_lighting=0.2, xtra_tfms=None)
data = ImageDataBunch.from_folder(path, ds_tfms=tfms, bs=64, size=296, test='test')
data.normalize(imagenet_stats)
learn = cnn_learner(data, models.resnet152, pretrained=True, metrics=[accuracy, top_k_accuracy, error_rate], callback_fns=ShowGraph)
learn.load('resnet152_one')
predict(img)
output: 681800513 which is correct
Using ImageDataBunch.single_from_classes
- incorrect output
import fastai
from fastai.vision import *
from fastai.widgets import *
from fastai.callbacks import *
from fastai.metrics import accuracy_thresh, top_k_accuracy, error_rate, FBeta, root_mean_squared_error, mean_squared_error, mean_absolute_error
path = Path('./data/0418_Combined')
tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=0.77, max_zoom=1.07,
max_lighting=0.2, max_warp=0.2, p_affine=0.2,
p_lighting=0.2, xtra_tfms=None)
classes = ['000937384', '000937385', '000937386', '003781800', '003781803', '003781805', '003781809', '003781811', '007812790',
'435470352', '435470353', '435470354', '605052578', '605052579', '605052580', '605052995', '605052996', '605052997',
'607930850', '607930851', '607930853', '607930855', '658620198', '658620199', '681800351', '681800352', '681800353',
'684620126', '684620127', '684620397', '000024463', '000024464', '000544179', '000544181', '000544182', '000544183',
'000544184', '000694220', '000711012', '000711013', '000711014', '000711015', '000711016', '000930753', '000932210',
'000933123', '000933125', '001725728', '001725729', '001850674', '003642337', '003781160', '003784250', '003786410',
'005910844', '005910900', '107020026', '107020027', '136680113', '136680114', '136680115', '433860356', '501110433',
'501110434', '591480006', '591480011', '620370710', '620370999', '633040693', '651620076', '651620077', '651620627',
'658620185', '658620448', '658620449', '659775036', '659775037', '669930060', '681800135', '681800136', '681800137',
'681800302', '681800303', '681800396', '681800397', '681800513', '681800517', '681800590', '681800591', '681800980',
'681800981', '683820022']
data_bunch = ImageDataBunch.single_from_classes(path, classes, ds_tfms=tfms, size=296).normalize(imagenet_stats)
learn = cnn_learner(data_bunch, models.resnet152, pretrained=False)
learn.load('resnet152_one')
predict(img)
output: 681800303 which is wrong
I am not sure why the difference and I am hoping someone can shed some light on this. I have been unable to get ImageDataBunch.from_folder
to work on render.
Cheers