hiya ive been making an image classifier and these source codes are from my university but when i use these codes i keep getting an error the source code was for a multiple image classifier i just changed the categorical to binary i think im doing something wrong but idk what
import numpy as np
import keras
from keras.layers import Dense,GlobalAveragePooling2D
from keras.optimizers import Adam
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Model
from sklearn.metrics import confusion_matrix
import itertools
import matplotlib.pyplot as plt
train_path=r'C:\Users\Acer\imagerec\Brain\TRAIN'
valid_path=r'C:\Users\Acer\imagerec\Brain\VAL'
test_path=r'C:\Users\Acer\imagerec\Brain\TEST'
class_labels=['yes', 'no']
train_batches=ImageDataGenerator(preprocessing_function=keras.applications.xception.preprocess_input)\
.flow_from_directory(train_path, target_size=(299,299),classes=class_labels,batch_size=5)
valid_batches=ImageDataGenerator(preprocessing_function=keras.applications.xception.preprocess_input)\
.flow_from_directory(train_path, target_size=(299,299),classes=class_labels,batch_size=5)
test_batches=ImageDataGenerator(preprocessing_function=keras.applications.xception.preprocess_input)\
.flow_from_directory(train_path, target_size=(299,299),classes=class_labels,batch_size=5, shuffle=False)
base_model=keras.applications.xception.Xception(include_top=False)
x=base_model.output
x=GlobalAveragePooling2D
x=Dense(1,activation='sigmoid')(x)
predictions=Dense(2,activation='Adam')(x)
for layer in base_model.layers:
layer.trainable=False
model=Model(inputs=base_model.input,outputs=predictions)
model.summary()
N=30
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
history=model.fit_generator(train_batches, steps_per_epoch=412,
validation_data=valid_batches,
validation_steps=35,epochs=N,verbose=1)
i get this error
2019-12-09 13:43:11.107461: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "C:\Users\Acer\Anaconda3\envs\condas\lib\site-packages\keras\engine\base_layer.py", line 310, in assert_input_compatibility
K.is_keras_tensor(x)
File "C:\Users\Acer\Anaconda3\envs\condas\lib\site-packages\keras\backend\tensorflow_backend.py", line 697, in is_keras_tensor
str(type(x)) + '`. '
ValueError: Unexpectedly found an instance of type `<class 'type'>`. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Acer/PycharmProjects/condas/nyah.py", line 28, in <module>
x=Dense(1,activation='sigmoid')(x)
File "C:\Users\Acer\Anaconda3\envs\condas\lib\site-packages\keras\backend\tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "C:\Users\Acer\Anaconda3\envs\condas\lib\site-packages\keras\engine\base_layer.py", line 446, in __call__
self.assert_input_compatibility(inputs)
File "C:\Users\Acer\Anaconda3\envs\condas\lib\site-packages\keras\engine\base_layer.py", line 316, in assert_input_compatibility
str(inputs) + '. All inputs to the layer '
ValueError: Layer dense_1 was called with an input that isn't a symbolic tensor. Received type: <class 'type'>. Full input: [<class 'keras.layers.pooling.GlobalAveragePooling2D'>]. All inputs to the layer should be tensors.