iamaaditya / VQA_Demo

Visual Question Answering Demo on pretrained model
http://iamaaditya.github.io/2016/04/visual_question_answering_demo_notebook
MIT License
242 stars 134 forks source link

Error predicting #26

Closed prem1215 closed 5 years ago

prem1215 commented 5 years ago

ValueError Traceback (most recent call last)

in 8 labelencoder = joblib.load(label_encoder_file_name) 9 for label in reversed(np.argsort(y_output)[0,-5:]): ---> 10 print(str(round(y_output[0,label]*100,2)).zfill(5), "% ",labelencoder.inverse_transform(label)) ~\Anaconda3\envs\VQA1\lib\site-packages\sklearn\preprocessing\label.py in inverse_transform(self, y) 271 """ 272 check_is_fitted(self, 'classes_') --> 273 y = column_or_1d(y, warn=True) 274 # inverse transform of empty array is empty array 275 if _num_samples(y) == 0: ~\Anaconda3\envs\VQA1\lib\site-packages\sklearn\utils\validation.py in column_or_1d(y, warn) 795 return np.ravel(y) 796 --> 797 raise ValueError("bad input shape {0}".format(shape)) 798 799 ValueError: bad input shape ()
WeiYangBin commented 5 years ago

I have solved the problem, we only need:

print("{} % {}!".format(round(y_output[0,label]*100,2), labelencoder.inverse_transform([label])[0]))

Because the inverse transform requires that we pass in an array

jiteshm17 commented 3 years ago

@WeiYangBin thank you so much for this. However, one thing to note is that this only works if the scikit-learn version is 0.21.1