I am trying to do multi-label classification using Keras. I got my dataset from kaggle.
Link to dataset: https://www.kaggle.com/dadajonjurakuziev/movieposter
I am getting an error when I am trying to fit the model.
THE CODE:
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=20, test_size=0.3)
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=(5, 5), activation="relu", input_shape=(SIZE,SIZE,3)))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(filters=32, kernel_size=(5, 5), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
model.add(Dropout(0.2))
model.add(Conv2D(filters=64, kernel_size=(5, 5), activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
model.add(Dropout(0.2))
model.add(Conv2D(filters=64, kernel_size=(5, 5), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(25, activation='sigmoid'))
model.summary()
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
#print(X_train, y_train, X_test, y_test)
history = model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test)) #This is the line where I am getting an error
THE ERROR:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type int).
Here are some values of X_train and y_train:
X_train[0]:
array([[[0.15294118, 0.1764706 , 0.3019608 ],
[0.15294118, 0.1764706 , 0.3019608 ],
[0.15686275, 0.18039216, 0.30588236],
...,
[0.69803923, 0.69411767, 0.75686276],
[0.69803923, 0.69411767, 0.75686276],
[0.69803923, 0.69411767, 0.75686276]],
[[0.11764706, 0.14509805, 0.25882354],
[0.11764706, 0.14509805, 0.25882354],
[0.12156863, 0.14509805, 0.27058825],
...,
[0.69411767, 0.6901961 , 0.7529412 ],
[0.69411767, 0.6901961 , 0.7529412 ],
[0.69411767, 0.6901961 , 0.7529412 ]],
[[0.10588235, 0.13333334, 0.24313726],
[0.10588235, 0.13333334, 0.24313726],
[0.10980392, 0.13725491, 0.2509804 ],
...,
[0.6901961 , 0.6862745 , 0.7490196 ],
[0.6901961 , 0.6862745 , 0.7490196 ],
[0.6901961 , 0.6862745 , 0.7490196 ]],
...,
[[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943],
...,
[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943]],
[[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943],
...,
[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943],
[0.16862746, 0.30588236, 0.62352943]],
[[0.1764706 , 0.31764707, 0.62352943],
[0.1764706 , 0.31764707, 0.62352943],
[0.1764706 , 0.31764707, 0.62352943],
...,
[0.1764706 , 0.31764707, 0.62352943],
[0.1764706 , 0.31764707, 0.62352943],
[0.1764706 , 0.31764707, 0.62352943]]], dtype=float32)
y_train[0]:
array(['https://m.media-amazon.com/images/M/MV5BY2IyODNmMjctMjNlNi00NmU0LTkxYTEtMTBjNzJiY2U0ZTI2XkEyXkFqcGdeQXVyMjI3MTc2MzU@._V1_UX256,0,256,256_AL_.jpg',
'The Lawyer', 2020, 7.1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
dtype=object)
I am not sure what the object dtype is. I am pretty new to these topics. Could someone please help me? Thanks!
intwhile keras expectsfloats. TryX = X.astype('float32')andY = Y.astype('float32')before doing anything else with them.