keras: invalid literal for int() with base 10: 'Participant1'
x_train.dat
contains my images and y_train.dat
contains my label however I when I try to train it with model.fit it keeps give me an error.
How I can run the model.compile
? Please help
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from pathlib import Path
import joblib
import matplotlib.pyplot as plt
# Load data set
x_train = joblib.load("x_train.dat")
y_train = joblib.load("y_train.dat")
epochs = 50
# Create a model and add layers
model = Sequential()
model.add(Flatten(input_shape=x_train.shape[1:]))
model.add(Dense(512, activation='relu', name='fc1'))
model.add(Dropout(0.3))
model.add(Dense(512, activation='relu', name='fc2'))
model.add(Dropout(0.3))
model.add(Dense(1, activation='relu', name='prediction'))
model.summary()
# compile model
# model.compile(loss='sparse_categorical_crossentropy', optimizer=optimizers.RMSprop(lr=2e-4), metrics=['accuracy'])
model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
from keras.utils import to_categorical
y_train = to_categorical(y_train)
history = model.fit(
x_train,
y_train,
epochs=epochs,
shuffle=True
)
# Save neural network structure
model_structure = model.to_json()
f = Path("model_structure.json")
f.write_text(model_structure)
# Save the model
model.save('vgg16_pretrained_2.h5')
# Check Performance
acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))
plt.plot(epochs, acc, 'b', label='Training acc')
plt.plot(epochs, val_acc, 'r', label='Validation acc')
plt.title('Training and validation accuracy')
plt.legend()
plt.figure()
plt.plot(epochs, loss, 'b', label='Training loss')
plt.plot(epochs, val_loss, 'r', label='Validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()
terminal output:
Using TensorFlow backend.
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
flatten_1 (Flatten) (None, 25088) 0
_________________________________________________________________
fc1 (Dense) (None, 512) 12845568
_________________________________________________________________
dropout_1 (Dropout) (None, 512) 0
_________________________________________________________________
fc2 (Dense) (None, 512) 262656
_________________________________________________________________
dropout_2 (Dropout) (None, 512) 0
_________________________________________________________________
prediction (Dense) (None, 1) 513
=================================================================
Total params: 13,108,737
Trainable params: 13,108,737
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
File "C:/Users/w024029h/PycharmProjects/keras_pretrained/2_training_image.py", line 29, in <module>
y_train = to_categorical(y_train)
File "C:\Users\w024029h\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\np_utils.py", line 25, in to_categorical
y = np.array(y, dtype='int')
ValueError: invalid literal for int() with base 10: 'Participant1'
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (4 by maintainers)
Yes.