Issue
i am trying to make an image classifier with keras to predict cases of breast câncer, i had some troubles until here because it's not a "simple" classifire, i couldn't do this with the traditional methods with keras. So i am trying to add more information than just a image, like an array [image, age, density]. I am new at this so i dont know if it's possible or how to search for the rigth way to do this, i am trying to do this this way:
X = np.array(X) \\ the image
y = np.array(y) \\ an array with 1 or 0 (cancer or not)
z = np.array(z) \\ the density of the breast
\ al the arrays correspond to the same case like X[0]
is the image y[0]
if this case is cancer or not and z[0]
the density os this case
model = Sequential()
model.add(Conv2D(64,(3,3), activation = 'relu'))
model.add(MaxPooling2D((2,2)))
model.add(Conv2D(64,(3,3), activation = 'relu'))
model.add(MaxPooling2D((2,2)))
model.add(Flatten())
model.add(Dense(128, input_shape = X.shape[1:],activation = 'relu'))
model.add(Dense(2,activation = 'softmax'))
model.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])
model.fit(X,z,y, epochs = 20) // i actually don't know how to give the information to the model
this is the error:
The truth value of an array with more than one element is ambiguous. Use a.any()
or a.all()
Solution
Fit does not take parameter like that. If you look at the function definition the first parameter is input, second is target prediction, and the third is batch size.
What you should do is concatenate X and z (and any other info), as they are both input data. e.g.
Xz = np.concatenate((X, z[..., np.newaxis]), axis=-1)
Note: z[..., np.newaxis]
takes an array with size [H, W]
and makes it [H, W, 1]
so that you can concatenate it with X, which I assume is an RGB image with shape [H,W,3]
. If it is greyscale, just ignore this and simple use z
.
Utimately what you want is the input to have dimension [H,W,C] where C is the dimension of all the data, e.g. [red, green, blue, age, density, etc]. It might make more sense in the network design to inject non-image information, like age, in at the final layers of the network (e.g. into Dense(128))
Answered By - geometrikal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.