Reputation: 189
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout,Activation,Flatten, Conv2D, MaxPooling2D
import pickle
import keras as ks
x1 =pickle.load(open("dX.pickle","rb"))
y2 =pickle.load(open("dY.pickle","rb"))
nx = x1/255.0
model = Sequential()
model.add(Conv2D(64,(3,3),input_shape = nx.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(64,3,3))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss = "binary_crossentropy", optimizer ="adam", metrics = ['accuracy'])
model.fit((nx,y2), batch_size = 20, validation_split =0.1,epochs=1)
img = image.load_img(r'img.png', target_size=(224,224))
prediction = model.prediction(img)
print(prediction)
I was following a tutorial https://www.youtube.com/watch?v=cAICT4Al5Ow&t=89s which shows you how to set up a simple neural network. But when I run the code it says.
tensorflow.python.framework.errors_impl.InvalidArgumentError:
You must feed a value for placeholder tensor 'activation_2_target' with dtype float and shape [?,?]
[[{{node activation_2_target}}]]
I was very confused where that number comes from since the tutorial never names it. I'm assuming it was abstracted by some class. Where do I define it?
Upvotes: 1
Views: 443
Reputation: 8585
Change this line
model.fit((nx,y2), batch_size=20, validation_split=0.1, epochs=1)
to this
model.fit(nx, y2, batch_size=20, validation_split=0.1, epochs=1)
You have provided only the train data in form of a tuple (nx, y2)
without the labels.
Upvotes: 2