Reputation: 1855
below imported packages and models which is define to allow to access the building operations,
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import cv2
import os
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing import image
from tensorflow.keras.optimizers import RMSpro
Now here is the coding of the created model, I think it is too importat to describe the model,
Rescale the images shapes,
train = ImageDataGenerator(rescale=1/255)
validation = ImageDataGenerator(rescale=1/255)
Fixed the dataset directory and access the data,
train_dataset = train.flow_from_directory(
'cnn_happy_NotHapp/Basedata/training/',
target_size=(200,200),
batch_size = 3,
class_mode = 'binary')
validation_dataset = validation.flow_from_directory(
'cnn_happy_NotHapp/Basedata/validation/',
target_size=(200,200),
batch_size = 3,
class_mode = 'binary')
Create the CNN model
model = tf.keras.models.Sequential([tf.keras.layers.Conv2D(16,(3,3), activation='relu', input_shape=(200, 200, 3)),
tf.keras.layers.MaxPool2D(2,2),
##################################
tf.keras.layers.Conv2D(132,(3,3), activation='relu'),
tf.keras.layers.MaxPool2D(2,2),
##################################
tf.keras.layers.Conv2D(64,(3,3), activation='relu'),
tf.keras.layers.MaxPool2D(2,2),
##################################
tf.keras.layers.Flatten(),
###################################
tf.keras.layers.Dense(512, activation='relu'),
###################################
tf.keras.layers.Dense(1, activation='sigmoid'),
])
Compile the model
model.compile(loss = 'binary_crossentropy',
optimizer = RMSprop(lr=0.001),
metrics = ['accuracy '])
Fit the model and please noticed here because i faced problem here,
model_fit = model.fit(train_dataset,
steps_per_epoch=3,
epochs= 10,
validation_data = validation_dataset) #error is here
Below the error section, I request all of stactoverflow members for carefully read and help me for solving this error,
Epoch 1/10
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-85ae786a1bf1> in <module>()
2 steps_per_epoch=3,
3 epochs= 10,
----> 4 validation_data = validation_dataset)
3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
805 # In this case we have created variables on the first call, so we run the
806 # defunned version which is guaranteed to never create variables.
--> 807 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable
808 elif self._stateful_fn is not None:
809 # Release the lock early so that multiple threads can perform the call
TypeError: 'NoneType' object is not callable
Note: I am suffering from this error , I can't solved it and advanced thanks who are try to solve it and comment here for sharing the answer
Upvotes: 3
Views: 6995
Reputation: 1855
@AlirezaMoradi please concern here,
I made a mistakes below,
In compile section of the model,
model.compile(loss = 'binary_crossentropy',
optimizer = RMSprop(lr=0.001),
metrics = ['accuracy ']) #'accuracy ' it will be 'accuracy'
That means,for my mistakes I add white space and after removing It solved.
I was busy that's why it is late for sharing the solution and I am sorry for late.
Upvotes: 5