advaitsave / Multiclass-Semantic-Segmentation-CamVid

Tensorflow 2 implementation of complete pipeline for multiclass image semantic segmentation using UNet, SegNet and FCN32 architectures on Cambridge-driving Labeled Video Database (CamVid) dataset.
82 stars 41 forks source link

model.fit_generator gave TypeError: 'NoneType' object is not callable #15

Open chuagh74 opened 3 years ago

chuagh74 commented 3 years ago

This is the error msg I got:


TypeError Traceback (most recent call last)

in 6 validation_data = ValAugmentGenerator(), 7 validation_steps = validation_steps, ----> 8 epochs=num_epochs, callbacks=callbacks) 9 model.save_weights("camvid_model_150_epochs.h5", overwrite=True) /cm/shared/apps/tensorflow2-py37-cuda10.2-gcc/2.2.0/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs) 322 'in a future version' if date is None else ('after %s' % date), 323 instructions) --> 324 return func(*args, **kwargs) 325 return tf_decorator.make_decorator( 326 func, new_func, 'deprecated', /cm/shared/apps/tensorflow2-py37-cuda10.2-gcc/2.2.0/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch) 1477 use_multiprocessing=use_multiprocessing, 1478 shuffle=shuffle, -> 1479 initial_epoch=initial_epoch) 1480 1481 @deprecation.deprecated( /cm/shared/apps/tensorflow2-py37-cuda10.2-gcc/2.2.0/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs) 64 def _method_wrapper(self, *args, **kwargs): 65 if not self._in_multi_worker_mode(): # pylint: disable=protected-access ---> 66 return method(self, *args, **kwargs) 67 68 # Running inside `run_distribute_coordinator` already. /cm/shared/apps/tensorflow2-py37-cuda10.2-gcc/2.2.0/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing) 846 batch_size=batch_size): 847 callbacks.on_train_batch_begin(step) --> 848 tmp_logs = train_function(iterator) 849 # Catch OutOfRangeError for Datasets of unknown size. 850 # This blocks until the batch has finished executing. /cm/shared/apps/tensorflow2-py37-cuda10.2-gcc/2.2.0/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds) 578 xla_context.Exit() 579 else: --> 580 result = self._call(*args, **kwds) 581 582 if tracing_count == self._get_tracing_count(): /cm/shared/apps/tensorflow2-py37-cuda10.2-gcc/2.2.0/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds) 609 # In this case we have created variables on the first call, so we run the 610 # defunned version which is guaranteed to never create variables. --> 611 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable 612 elif self._stateful_fn is not None: 613 # Release the lock early so that multiple threads can perform the call TypeError: 'NoneType' object is not callable
nikithanair95 commented 3 years ago

Did you get a solution to this error?

chuagh74 commented 3 years ago

yes. That's because I was not using right version of TF

nikithanair95 commented 3 years ago

Which version did you use to get it right?

chuagh74 commented 3 years ago

According to my technical support, we were using keras ....we should use tf keras....so he removed keras and use tf keras

nikithanair95 commented 3 years ago

We are importing tenserflow.keras everywhere still we are getting error. Could you please tell me where did you exactly change in the code ?

chuagh74 commented 3 years ago

It was very long ago and i can't remember exactly. But what i remembered is we removed keras and reinstalled tensorflow and change import of keras to tensorflow.keras

from tensorflow.keras.models import Model from tensorflow.keras.regularizers import l2 from tensorflow.keras.layers import *

from tensorflow.keras.engine import Layer

from tensorflow.keras.applications.vgg16 import from tensorflow.keras.models import

from tensorflow.keras.applications.imagenet_utils import _obtain_input_shape

import tensorflow.keras.backend as K import tensorflow as tf from tensorflow.keras.optimizers import Adam from tensorflow.keras.layers import Convolution2D, ZeroPadding2D, MaxPooling2D, Cropping2D, Conv2D from tensorflow.keras.layers import Input, Add, Dropout, Permute, add from tensorflow.compat.v1.layers import conv2d_transpose from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.python.keras.callbacks import TensorBoard, ModelCheckpoint, EarlyStopping, ReduceLROnPlateau