Home>
ValueError: Error when checking input: expected conv2d_4_input to have 4 dimensions, but got array with shape (0, 1)
I am in trouble with the error.
For sites i am referring to
input_shape = X_train.shape [1:]
Then you get an error
input_shape = (64, 64, 3)
Changed to
Is the error message shape (0, 1) meaning that there is no data because the usage of input_shape is wrong
Applicable source code# coding: utf-8
import keras
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers.convolutional import Conv2D, MaxPooling2D
from keras.layers.core import Dense, Dropout, Activation, Flatten, Reshape
import numpy as np
from sklearn.model_selection import train_test_split
from PIL import Image
import glob
folder = ["cat", "lion", "dog", "woman"]
image_size = 50
X = []
Y = []
for index, name in enumerate (folder):
dir = "./" + name
files = glob.glob (dir + "/*.jpg")
for i, file in enumerate (files):
image = Image.open (file)
image = image.convert ("RGB")
image = image.resize ((image_size, image_size))
data = np.asarray (image)
X.append (data)
Y.append (index)
X = np.array (X)
Y = np.array (Y)
X = X.astype ('float32')
X = X/255.0
# Convert correct label format
Y = np_utils.to_categorical (Y, 4)
# Learning data and test data
X_train, X_test, y_train, y_test = train_test_split (X, Y, test_size = 0.20)
# Build CNN
model = Sequential ()
model.add (Conv2D (32, (3, 3), padding = 'same', input_shape = (64, 64, 3)))
model.add (Activation ('relu'))
model.add (Conv2D (32, (3, 3)))
model.add (Activation ('relu'))
model.add (MaxPooling2D (pool_size = (2, 2)))
model.add (Dropout (0.25))
model.add (Conv2D (64, (3, 3), padding = 'same'))
model.add (Activation ('relu'))
model.add (Conv2D (64, (3, 3)))
model.add (Activation ('relu'))
model.add (MaxPooling2D (pool_size = (2, 2)))
model.add (Dropout (0.25))
model.add (Flatten ())
model.add (Dense (512))
model.add (Activation ('relu'))
model.add (Dropout (0.5))
model.add (Dense (4))
model.add (Activation ('softmax'))
model.summary ()
model.compile (loss = 'categorical_crossentropy',
optimizer = 'SGD',
metrics = ['accuracy'])
history = model.fit (X_train, y_test, epochs = 20)
-
Answer # 1
Related articles
- python 27 - keras with python27
- python - image recognition using cnn keras multiple inputs
- i don't understand the exercises using python trigonometric functions
- about batch change of file name using python
- python - image recognition with keras
- python - i want to move images with pygame
- python - i'm using selenium the text sent by send_keys to the input tag disappears when the text is sent by send_key to the next
- please explain the function using the python dictionary
- parameter estimation using python's weighted least squares method (wls)
- parallel processing using python multiprocessingpool and multiprocessingqueue does not work well
- about external libraries when using multiple versions of python
- python - i want to separate by a specific word using the split function
- python - i want to design a cnn with 2 inputs and 1 output with keras
- python 3x - i want to get the nth array with an argument using python3 argparse
- python - the link created with the collected path does not open
- python 3x - how to rename a folder created using jupyternotebook
- python 3x - processing to jump to the link destination using chrome driver in python
- python - error in image binarization using cv2adaptivethreshold function
- i want to adjust the execution result using the while statement in python as expected
- python - i want to put the image file path in a variable and open it using that variable
Related questions
- python 3x - tensorflow modelpredict () error
- python 3x - inflating table data using gan
- python 3x - keras predict results do not change
- python - loss coefficient does not decrease at all | stock price forecast using deep learning
- python 3x - about python keras model building
- python 3x - python keras about the shape of learning data
- python - about learning mnist data with keras
- resizing the output image with ipythondisplay on jupyter notebook
- python - error that no data is entered in x_train_b
- python - i want to resolve the error message
input data must be input_shape = (number of data, 64, 64, 3).
Take another step and try to shape it.