Home>
Currently, I am trying to estimate the position using only images.
I think that it will be easier to estimate by using two images (before and after myself) for input.
I'm doing it, but I get the following error and I don't know what to do.
I would like you to tell me.
If there are any other strange points, I would appreciate it if you could let me know.
* The classes of classes are changed appropriately.
ValueError: Layer reshape_1 was called with an input that isn't a symbolic tensor. Received type:<class'builtin_function_or_method'>. Full input: [<built-in function input>]. All inputs to the layer should be tensors.
Corresponding source code
from keras import backend as K
from keras.datasets import mnist
from keras.layers import Activation, Add, BatchNormalization, Dense, Dropout, Input, Concatenate, Flatten, Reshape
from keras.models import Model
from keras.utils.np_utils import to_categorical
import matplotlib.pyplot as plt
import numpy as np
import glob
from PIL import Image
from keras.utils import np_utils
from sklearn.model_selection import train_test_split
from keras.preprocessing.image import load_img, img_to_array
classes = [
"Dog", "Cat", "Rabbit"
]
X = []
Y = []
for index, classlabel in enumerate (classes):
dir = "./" + classlabel
files = glob.glob (dir + "/*.jpg")
for i, file in enumerate (files):
image = Image.open (file)
image = image.convert ("RGB")
image = image.resize ((64, 64))
data = np.asarray (image)
X.append (data)
Y.append (index)
X = np.array (X)
Y = np.array (Y)
X = X.astype ('float32') /255.0
Y = np_utils.to_categorical (Y, len (classes))
x_train, x_test, y_train, y_test = train_test_split (X, Y, test_size = 0.10)
# Randomly cut out two images from each image.
x_train1_img = load_img ('1.jpg', target_size = (64,64))
x_train1 = img_to_array (x_train1_img)
x_train2_img = load_img ('2.jpg', target_size = (64,64))
x_train2 = img_to_array (x_train2_img)
# (N, 2, 28, 28)->(N, 2, 400)
x_train1 = x_train.reshape (len (x_train1), 2, -1)
x_train2 = x_train.reshape (len (x_train2), 2, -1)
x_test = x_test.reshape (len (x_test), 2, -1)
Convert to # one-hot representation.
y_train = to_categorical (y_train)
y_test = to_categorical (y_test)
#Create a model.
input1 = Input (shape = (1,))
hidden1 = Reshape ((64, 64, 1), input_shape = (64, 64)) (input)
input2 = Input (shape = (1,))
hidden2 = Reshape ((64, 64, 1), input_shape = (64, 64)) (input)
# From input 1 to before joining
x = Dense (1, activation = "relu") (hidden1)
x = Model (inputs = hidden1, outputs = x)
# From input 2 to before joining
y = Dense (1, activation = "relu") (hidden2)
y = Model (inputs = hidden2, outputs = y)
# Join
combined = Concatenate ([x.output, y.output], axis = -1)
# Tightly coupled
z = Dense (32, activation = "relu") (combined)
z = Dense (3, activation = "softmax") (z)
#Model definition and compilation
model = Model (inputs = [input1, input2], outputs = z)
model.compile (loss ='binary_crossentropy', optimizer ='adam', metrics = ['acc'])
model.summary ()
# learn.
history = model.fit ([x_train1, x_train2], y_train, epochs = 40)
What I tried
I searched for the above error, but it didn't work.
-
Answer # 1
Related articles
- python - image recognition with keras
- python - error in image binarization using cv2adaptivethreshold function
- python - i want to put the image file path in a variable and open it using that variable
- python - how to input grayscale image to keras vgg16 model (imagedatagenerator)
- python 3x - when saving an image using python, it cannot be saved (output) again with the same file name
- python - i want to convert a black and white image to an arbitrary color image
- python 3x - i want to get the nth array with an argument using python3 argparse
- python - i want to display an image with pysimplegui, but an error occurs
- about batch change of file name using python
- python - i want to divide the read image into pixels and label them
- python - i want to create a contour image
- python 3x - how to rename a folder created using jupyternotebook
- python - i want to design a cnn with 2 inputs and 1 output with keras
- python - i want to read an image and display it
- python - i want to separate by a specific word using the split function
- css - image does not resize well when using "position: absolute"
- how to save the image ocr result file in python
- python 3x - processing to jump to the link destination using chrome driver in python
- python - about image display and position of main ()
Related questions
- python : About the size of y_pred, y_true in Keras
- python : Working with a small amount of data for binary classification in neural networks
- python : RESOURCEEXHAUSTEDERRORRORR ERROR During neural network training
- python : Valueerror error: Invalid Literal for int () with Base 10 When running Estimator.Train string (input_fn= train_input_fn
- python : 95% Accuracy Predicts Wrong Class (Multiclass Classification Kaggle GTSRB -German Traffic Sign Recognition Benchmark)
- python : TensorFlow Cudart64_101.dll Not Found
- python : How to make the neural set classify the text?
- Using Weights in FIT () with Python Keras-RL
- python : Permissionerror: [errno 13] permission denied
I don't know if the learning accuracy will be correct, but I will show the code that works without error.
The main questions in the questioner's code are as follows. I fixed that point.
For some reason, the pre-processing is limited to only two images.
In the model creation part, the input dimension of the site referenced by the questioner is completely different. It does not apply to the situation of the questioner. By the way, since the questioner is premised on images, I have included a CNN layer.
As I looked through the code, I referred to an example of a "merge model" in Keras. According to it, I think that the basic pattern is to merge completely different learning results such as images and text. I think that merging equivalent images and images like the questioner is essentially the same as synthesizing images into one and learning with a normal model.