Verifying downloaded model

Hi,

I have created and downloaded trained model after running titanic survival classification model. Now I want to verify if downloaded trained model is working fine or not. For this, I am executing following command from command prompt:

E:\python-codes>python3 test.py test.csv

But getting following errors:

C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\h5py_init_.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
outputs will be stored at ‘./output/’

aborting due to exception… Please check input file format!
Traceback (most recent call last):
File “C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\pandas\core\indexes\base.py”, line 2525, in get_loc
return self._engine.get_loc(key)
File “pandas/_libs/index.pyx”, line 117, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/index.pyx”, line 139, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 1265, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 1273, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘sex’

I guess there is specific way to create .csv file to test trained model. Could you please elaborate on this.

Thanks a lot.

Rizwan, the test.csv needs to be in the same format as train.csv except that test.csv does not need to have the output column.

Could you try running it on train.csv first to make sure it is not an issue with CSV file format?

Dear Rajendra,

I just ran already built project in DLS. I don’t know where to find train.csv. Please do let me know how can I find the format of train.csv or test.csv.

Thanks a lot.

You can find train.csv for public datasets in <DLS_INSTALL_LOCATION>\data\public\datasets\<dataset_name>\train.csv

Thank you Rajendra!

Now I am trying to verify / test downloaded model for MNIST classification. The input for this model is an image. As per train.csv, its in this format:

|Digit Label |Image|
|5| ./images/5/35.png

I have created test.csv exactly similar and created folder in the same order to put test image. But when I am running test.py I am getting this error:

C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\h5py_init_.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
outputs will be stored at ‘./output/’

aborting due to exception… Please check input file format!
Traceback (most recent call last):
File “test.py”, line 227, in test_model
os.path.dirname(input_file), test_raw, data_mapping)
File “test.py”, line 81, in process_test_input
img = scipy.misc.imread(base_dir + “/” + test_raw[col_name][0])
File “C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\numpy\lib\utils.py”, line 101, in newfunc
return func(*args, **kwds)
File “C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\scipy\misc\pilutil.py”, line 164, in imread
im = Image.open(name)
File “C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\PIL\Image.py”, line 2543, in open
fp = builtins.open(filename, “rb”)
FileNotFoundError: [Errno 2] No such file or directory: ‘/./images/5/35.png’

Rizwan, can you show me the command you ran ?

seems like base_dir is empty. Try specifying the absolute path of test.csv file so that base_dir gets set.

I am running the command form the same directory where test.py and test.csv and downloaded model is located.

E:\python-codes\MNISTHandwrittenDigitsClassifier_0>python test.py test1.csv

ok. I am assuming images are present in E:\python-codes\MNISTHandwrittenDigitsClassifier_0\images folder.

Can you run following:

python test.py E:\python-codes\MNISTHandwrittenDigitsClassifier_0\test1.csv

Ok, now it got executed but I can’t find output file!

output should be generated in test_result.csv file. You do not have this file after command is done ?

Nope, I don’t have this file.

This is what I have on screen:

C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\h5py_init_.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
outputs will be stored at ‘./output/’

C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\topology.py:1271: UserWarning: Update your InputLayer call to the Keras 2 API: InputLayer(name="Input_1", sparse=False, dtype="float32", batch_input_shape=[None, 1, ...)
return cls(**config)
C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\topology.py:1271: UserWarning: Update your Dense call to the Keras 2 API: Dense(trainable=True, kernel_constraint=None, input_dim=784, bias_constraint=None, kernel_regularizer=None, use_bias=True, activity_regularizer=None, name="Dense_1", bias_regularizer=None, units=512, activation="relu", kernel_initializer="glorot_uniform")
return cls(**config)
C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\topology.py:1271: UserWarning: Update your Dropout call to the Keras 2 API: Dropout(trainable=True, name="Dropout_1", rate=0.3)
return cls(**config)
C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\topology.py:1271: UserWarning: Update your Dense call to the Keras 2 API: Dense(trainable=True, kernel_constraint=None, input_dim=512, bias_constraint=None, kernel_regularizer=None, use_bias=True, activity_regularizer=None, name="Dense_2", bias_regularizer=None, units=512, activation="relu", kernel_initializer="glorot_uniform")
return cls(**config)
C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\topology.py:1271: UserWarning: Update your Dropout call to the Keras 2 API: Dropout(trainable=True, name="Dropout_2", rate=0.3)
return cls(**config)
C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\topology.py:1271: UserWarning: Update your Dense call to the Keras 2 API: Dense(trainable=True, kernel_constraint=None, input_dim=512, bias_constraint=None, kernel_regularizer=None, use_bias=True, activity_regularizer=None, name="Dense_3", bias_regularizer=None, units=10, activation="softmax", kernel_initializer="glorot_uniform")
return cls(**config)
2018-06-01 13:01:20.022619: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
aborting due to exception… Please check input file format!
Traceback (most recent call last):
File “test.py”, line 249, in test_model
res = customPredict(test_data, config, modelFile)
File “test.py”, line 213, in customPredict
return mod.predict(test_data)
File “C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\training.py”, line 1817, in predict
check_batch_axis=False)
File “C:\Users\Rizwan.Khan\AppData\Local\conda\conda\envs\py35\lib\site-packages\keras\engine\training.py”, line 123, in _standardize_input_data
str(data_shape))
ValueError: Error when checking : expected Input_1 to have shape (1, 28, 28) but got array with shape (28, 28, 1)

ok. Last line in the log is the reason why your command failed.

can you try commenting following two lines (around line# 104 in test.py) which is transposing the shape:

    if K.image_dim_ordering() == 'tf':
        test_data[i] = np.transpose(test_data[i], (0, 2, 3, 1))

It worked !

Thanks a lot.