Try to search your question here, if you can't find : Ask Any Question Now ?

How to fix Error when checking target: expected activation_5 to have 2 dimensions, but got array with shape (24943, 50, 50, 1)

HomeCategory: stackoverflowHow to fix Error when checking target: expected activation_5 to have 2 dimensions, but got array with shape (24943, 50, 50, 1)
gaurav asked 2 weeks ago

I’m constructing a CNN to predict cats and dogs from kaggle (filetype: jpg). I use a tensorflow backend in an anaconda environment with Python 3.6. But I get this error:

ValueError: Error when checking target: expected activation_8 to have 2 dimensions, but got array with shape (24943, 50, 50, 1)

import tensorflow as tf
from tensorflow.keras.datasets import cifar10
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
import pickle
pickle_in = open("X.pickle","rb")
X = pickle.load(pickle_in)
pickle_in = open("y.pickle","rb"`
y = pickle.load(pickle_in)
X = X/255.0
model = Sequential()
model.add(Conv2D(256, (3, 3), input_shape=X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())  # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Dense(1))
model.add(Activation('sigmoid')) 
model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
model.fit(X, y, batch_size=32, epochs=3, validation_split=0.3)
1 Answers
Best Answer
Mannu answered 2 weeks ago
Your Answer

15 + 18 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com