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

Imdadul Haque
  • 1,635
  • 5
  • 23
  • 44
  • Does this answer your question? [Python NoneType object is not callable (beginner)](https://stackoverflow.com/questions/9768865/python-nonetype-object-is-not-callable-beginner) – takendarkk Sep 11 '20 at 18:35
  • No, I have seen that and try to understand but i don't. – Imdadul Haque Sep 12 '20 at 01: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`. – CryptoFool Sep 12 '20 at 04:07
  • Imdadul Haque, Is your issue resolved now? Else, please can you share complete code or Colab file to replicate your issue. Thanks! –  Oct 05 '20 at 11:49
  • @ImdadulHaque have you managed to solve the issue? It seems kinda new and there's no proper answer for it. – Alireza Moradi Oct 05 '20 at 16:21
  • @AlirezaMoradi, yea, I could solve it. – Imdadul Haque Oct 05 '20 at 17:13
  • @ImdadulHaque Could you share how you solved it? – Alireza Moradi Oct 06 '20 at 04:42
  • @AlirezaMoradi Please follow the answer. – Imdadul Haque Oct 07 '20 at 04:34

1 Answers1

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.

Imdadul Haque
  • 1,635
  • 5
  • 23
  • 44