3

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

8
  • Does this answer your question? Python NoneType object is not callable (beginner) Commented Sep 11, 2020 at 18:35
  • No, I have seen that and try to understand but i don't. Commented Sep 12, 2020 at 1:43
  • This seems to be telling you that the value self._stateless_fn is None, which doesn't work when you treat it like a function and try to call it. I don't know the modules being used here, so maybe this isn't as simple as I'm making it, but...your code doesn't mention _stateless_fn at all, so there's no way for us to know why it is None. Commented Sep 12, 2020 at 4:07
  • Imdadul Haque, Is your issue resolved now? Else, please can you share complete code or Colab file to replicate your issue. Thanks! Commented Oct 5, 2020 at 11:49
  • @ImdadulHaque have you managed to solve the issue? It seems kinda new and there's no proper answer for it. Commented Oct 5, 2020 at 16:21

1 Answer 1

5

@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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.