1

I am writing to ask a follow-up question regarding the answer provided here: Keras model.fit UnboundLocalError

The answer provided by @ivan_pozdeev reads: In engine/training.py,

elif data.__class__.__name__ == 'DataFrame':
    # test if data is a DataFrame, without pandas installed
    data = data.values

should be

elif data.__class__.__name__ == 'DataFrame':
    # test if data is a DataFrame, without pandas installed
    arrays = data.values

In response to ivan_pozdeev's answer, I made the suggested change in training.py: I changed 'data' to 'arrays' in the suggested line of the code. However, I am still getting an error that reads:

 File "/home/user/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1555, in fit
class_weight=class_weight,
  File "/home/user/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1413, in _standardize_user_data
output_shapes,
  File "/home/user/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 126, in _standardize_input_data
# Make arrays at least 2D.
UnboundLocalError: local variable 'arrays' referenced before assignment

Copied and pasted below, please find details of my data:

X_train shape: (83, 600, 800, 3);
Y_train shape: (83, 2);
X_test shape: (17, 600, 800, 3);
Y_test shape: (17, 2);

X_train and X_test are 'numpy.ndarray.'

Y_train and Y_test are 'pandas.core.frame.DataFrame.'

As a brief description of my data, X_train and X_test were created from png files:

from PIL import Image
images = glob('*.png')

a = []
for k in range(0, 100):      
    image = images[k]
    arr = np.array(Image.open(image).convert('RGB'))
    a.append(arr)
new_a = np.stack(a, axis=0)
Xdataset = new_a

where Xdataset was split randomly into X_train and X_test.

Ydataset was extracted from a csv file as a pandas dataframe:

Ydataset = pd.read_csv("Mod_Rate.csv", sep=',')

Ydataset was randomly divided into Y_train and Y_test. Ydataset has two columns with numeric (float64) values, representing two different parameter values.

Input data, X_train and X_test, are fed into a CNN. The output, Y_train and Y_test, consists of two columns of numeric values, i.e. regression prediction values of 2 parameters.

I am new to keras. My question is -- in addition to @ivan_pozdeev's answer, what else could I do to resolve the errors I am getting? Your advice would be much appreciated.

0 Answers0