infer.py can not produce test result?
dxiaosa opened this issue · 2 comments
When I use FCN32s_model_iter_xxx.h5 to test image, everything is ok. However, when using FCN16s_model_iter_xxx.h5 in "infer.py":
if osp.basename(chainermodel).lower().startswith('fcn32s'):
model_class = fcn.models.FCN32s
elif osp.basename(chainermodel).lower().startswith('fcn16s'):
model_class = fcn.models.FCN16s
elif osp.basename(chainermodel).lower().startswith('fcn8s'):
model_class = fcn.models.FCN8s
else:
raise ValueError
model = model_class(n_class=len(dataset.label_names))
chainer.serializers.load_hdf5(chainermodel, model)
infer = fcn.Inferencer(dataset, model, gpu)
for img_file in img_files:
img, label = infer.infer_image_file(img_file)
out_img = infer.visualize_label(img, label)
out_file = osp.join(save_dir, osp.basename(img_file))
scipy.misc.imsave(out_file, out_img)
print('- out_file: {0}'.format(out_file))
error occurs:
File "", line 48, in main
img, label = infer.infer_image_file(img_file['img'])
File "/home/dxiaosa/anaconda2/lib/python2.7/site-packages/fcn/inferencer.py", line 43, in infer_image_file
label = self.infer(x)
File "/home/dxiaosa/anaconda2/lib/python2.7/site-packages/fcn/inferencer.py", line 26, in infer
self.model(x)
File "/home/dxiaosa/anaconda2/lib/python2.7/site-packages/fcn/models/fcn16s.py", line 145, in call
self.loss = F.softmax_cross_entropy(self.score, t, normalize=False)
File "/home/dxiaosa/anaconda2/lib/python2.7/site-packages/chainer-1.18.0-py2.7-linux-x86_64.egg/chainer/functions/loss/softmax_cross_entropy.py", line 169, in softmax_cross_entropy
return SoftmaxCrossEntropy(use_cudnn, normalize, cache_score)(x, t)
File "/home/dxiaosa/anaconda2/lib/python2.7/site-packages/chainer-1.18.0-py2.7-linux-x86_64.egg/chainer/function.py", line 182, in call
for x in inputs]
File "/home/dxiaosa/anaconda2/lib/python2.7/site-packages/chainer-1.18.0-py2.7-linux-x86_64.egg/chainer/variable.py", line 95, in init
raise TypeError(msg)
TypeError: numpy.ndarray or cuda.ndarray are expected.
Actual: <type 'NoneType'>
How can i do? thx.
It is strange, because if t is None, loss won't be computed:
https://github.com/wkentaro/fcn/blob/master/fcn/models/fcn16s.py#L132-L134
Please make sure your fcn is latest.
I confirmed that it works:
./infer.py -m ~/data/models/chainer/fcn16s_from_caffe.npz -i <IMG_FILE>