lim-anggun / FgSegNet

FgSegNet: Foreground Segmentation Network, Foreground Segmentation Using Convolutional Neural Networks for Multiscale Feature Encoding
https://doi.org/10.1016/j.patrec.2018.08.002
Other
240 stars 76 forks source link

Issue when training #7

Closed theimgclist closed 6 years ago

theimgclist commented 6 years ago

I followed the steps mentioned in the README. After I downloaded the dataset and placed it in the right directory, I used FgSegNet.py to start the training. Pasting below the error log:

(50, 240, 320, 3) (50, 120, 160, 3) (50, 60, 80, 3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/FgSegNet/FgSegNet/FgSegNet.py in <module>()
    219 
    220         results = generateData(train_dir, dataset_dir, scene)
--> 221         train(results, scene, mdl_path, log_dir, vgg_weights_path)
    222         del results

/FgSegNet/FgSegNet/FgSegNet.py in train(results, scene, mdl_path, log_dir, vgg_weights_path)
    141     img_shape = results[0][0].shape
    142     model = FgSegNetModule(lr, reg, img_shape, scene, vgg_weights_path)
--> 143     model = model.initModel()
    144 
    145     tb = keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=0, batch_size=batch_size, write_graph=False, write_grads=True, write_images=True, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None)

/content/FgSegNet/FgSegNet/FgSegNetModule.py in initModel(self)
     85 
     86         input_1 = Input(shape=(h, w, d), name='ip_scale1')
---> 87         vgg_layer_output = self.VGG16(input_1)
     88         shared_model = Model(inputs=input_1, outputs=vgg_layer_output, name='shared_model')
     89         shared_model.load_weights(self.vgg_weights_path, by_name=True)

/content/FgSegNet/FgSegNet/FgSegNetModule.py in VGG16(self, x)
     27 
     28         # Block 1
---> 29         x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1', data_format='channels_last')(x)
     30         x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(x)
     31         x = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(x)

/usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     89         return wrapper
     90     return legacy_support
---> 91 
     92 
     93 generate_legacy_method_interface = functools.partial(generate_legacy_interface,

/usr/local/lib/python3.6/dist-packages/keras/layers/convolutional.py in __init__(self, filters, kernel_size, strides, padding, data_format, dilation_rate, activation, use_bias, kernel_initializer, bias_initializer, kernel_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, bias_constraint, **kwargs)
    439                  bias_constraint=None,
    440                  **kwargs):
--> 441         super(Conv2D, self).__init__(
    442             rank=2,
    443             filters=filters,

TypeError: super(type, obj): obj must be an instance or subtype of type 

Did I miss something?

Mary2333 commented 6 years ago

Hi,Do you know how to solve the following issue? thank you for helping me. ImportError Traceback (most recent call last) /apsarapangu/disk6/wuting/FgSegNet/FgSegNet-master/FgSegNet/FgSegNet.py in () 31 from skimage.transform import pyramid_gaussian 32 from sklearn.utils import compute_class_weight ---> 33 from FgSegNetModule import FgSegNetModule 34 from keras.utils.data_utils import get_file 35

/apsarapangu/disk6/wuting/FgSegNet/FgSegNet-master/FgSegNet/FgSegNetModule.py in () 11 from keras.models import Model 12 from keras.layers import Activation, Input, Dropout ---> 13 from keras.layers.convolutional import Conv2D, Conv2DTranspose, UpSampling2D, Cropping2D, MyUpSampling2D 14 from keras.layers.pooling import MaxPooling2D 15 from keras import regularizers

ImportError: cannot import name 'MyUpSampling2D'

theimgclist commented 6 years ago

Hi @Mary233. The error must be because of not properly copying the utils files that were shared. In the project's readme file, they have given us the instructions to copy the files from utils folder into the installed keras directory.

The file convolutional.py from utils folder has the class MyUpSampling2D. This class does not exist in the convolutional.py file which exists by default in keras installation. Try copying the convolutional.py file from utils into your keras directory at the path keras/layers/convolutional.py. As mentioned this file already exists so you have to replace it.

Mary2333 commented 6 years ago

Thank you very much! I solved the issue by your answer. and, I have another issue, do you know how to solve it? thanks again! when I run the FgSegNet.py, the following issue occured.

Training ->>> PTZ / twoPositionPTZCam (50, 340, 570, 3) (50, 170, 285, 3) (50, 85, 143, 3)

ValueError Traceback (most recent call last) /apsarapangu/disk6/wuting/FgSegNet/FgSegNet-master/FgSegNet/FgSegNet.py in () 219 220 results = generateData(train_dir, dataset_dir, scene) --> 221 train(results, scene, mdl_path, log_dir, vgg_weights_path) 222 del results

/apsarapangu/disk6/wuting/FgSegNet/FgSegNet-master/FgSegNet/FgSegNet.py in train(results, scene, mdl_path, log_dir, vgg_weights_path) 147 redu = keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=reduce_factor, patience=num_patience, verbose=1, mode='auto', epsilon=0.0001, cooldown=0, min_lr=0) 148 model.fit([results[0], results[1], results[2]], results[3], validation_split=0.2, epochs=epoch, batch_size=batch_size, --> 149 callbacks=[redu, chk, tb], verbose=1, class_weight=results[4], shuffle = True) 150 151 del model, results, tb, chk, redu

/apsarapangu/disk6/wuting/Anaconda3/lib/python3.5/site-packages/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, **kwargs) 1356 class_weight=class_weight, 1357 check_batch_axis=False, -> 1358 batch_size=batch_size) 1359 # Prepare validation data. 1360 if validation_data:

/apsarapangu/disk6/wuting/Anaconda3/lib/python3.5/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size) 1232 self._feed_input_shapes, 1233 check_batch_axis=False, -> 1234 exception_prefix='input') 1235 y = _standardize_input_data(y, self._feed_output_names, 1236 output_shapes,

/apsarapangu/disk6/wuting/Anaconda3/lib/python3.5/site-packages/keras/engine/training.py in _standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix) 138 ' to have shape ' + str(shapes[i]) + 139 ' but got array with shape ' + --> 140 str(array.shape)) 141 return arrays 142

ValueError: Error when checking input: expected ip_scale3 to have shape (None, 85, 142, 3) but got array with shape (50, 85, 143, 3)

Mary2333 commented 6 years ago

You can try to check the version of your keras, the right version is keras2.0.6