Mask_rcnn: RuntimeError

Created on 11 Sep 2018  路  12Comments  路  Source: matterport/Mask_RCNN

File "C:\Users\SIDDHESHWARAnaconda3\lib\site-packages\keras\engine\network.py", line 317, in __setattr__
'It looks like you are subclassing Model and you '

RuntimeError: It looks like you are subclassing Model and you forgot to call super(YourClass, self).__init__(). Always start with this line.

Most helpful comment

Solved by changing code in mrcnn/parallel_model.py as the following:

class ParallelModel(KM.Model):
    def __init__(self, keras_model, gpu_count):
        """Class constructor.
        keras_model: The Keras model to parallelize
        gpu_count: Number of GPUs. Must be > 1
        """
        super(ParallelModel, self).__init__()
        self.inner_model = keras_model
        self.gpu_count = gpu_count
        merged_outputs = self.make_parallel()
        super(ParallelModel, self).__init__(inputs=self.inner_model.inputs,
                                            outputs=merged_outputs)

All 12 comments

same problem!!!!!
when I want to train by mult-GPU,
RuntimeError: It looks like you are subclassing Model and you forgot to call super(YourClass, self).__init__(). Always start with this line.

Same issue here as well.
When GPU_COUNT > 1

pip3 install keras==2.1.3. This solves the issue for training, you can train on multi GPU. It won't work for inference, because keras don't have savings in 2.1.3 build.

Solved by changing code in mrcnn/parallel_model.py as the following:

class ParallelModel(KM.Model):
    def __init__(self, keras_model, gpu_count):
        """Class constructor.
        keras_model: The Keras model to parallelize
        gpu_count: Number of GPUs. Must be > 1
        """
        super(ParallelModel, self).__init__()
        self.inner_model = keras_model
        self.gpu_count = gpu_count
        merged_outputs = self.make_parallel()
        super(ParallelModel, self).__init__(inputs=self.inner_model.inputs,
                                            outputs=merged_outputs)

Solved by changing code in mrcnn/parallel_model.py as the following:

class ParallelModel(KM.Model):
    def __init__(self, keras_model, gpu_count):
        """Class constructor.
        keras_model: The Keras model to parallelize
        gpu_count: Number of GPUs. Must be > 1
        """
        super(ParallelModel, self).__init__()
        self.inner_model = keras_model
        self.gpu_count = gpu_count
        merged_outputs = self.make_parallel()
        super(ParallelModel, self).__init__(inputs=self.inner_model.inputs,
                                            outputs=merged_outputs)

When change code in your way, It still has error, asking for two arguments: inputs and outputs

Solved by changing code in mrcnn/parallel_model.py as the following:

class ParallelModel(KM.Model):
    def __init__(self, keras_model, gpu_count):
        """Class constructor.
        keras_model: The Keras model to parallelize
        gpu_count: Number of GPUs. Must be > 1
        """
        super(ParallelModel, self).__init__()
        self.inner_model = keras_model
        self.gpu_count = gpu_count
        merged_outputs = self.make_parallel()
        super(ParallelModel, self).__init__(inputs=self.inner_model.inputs,
                                            outputs=merged_outputs)

When change code in your way, It still has error, asking for two arguments: inputs and outputs

Sorry, It works. My bad. Thank you!

@shen338
When I think you changed the above, I got an error, suggesting that I need two parameters, one input, one output, how do you solve this error?

image

I got the result of training only does a single change :
Step 1 :
pip3 install keras==2.1.3.

Step 2:
Don't change any line of code and run the file again!


I got good accuracy 馃憤

image

Solved by changing code in mrcnn/parallel_model.py as the following:

class ParallelModel(KM.Model):
    def __init__(self, keras_model, gpu_count):
        """Class constructor.
        keras_model: The Keras model to parallelize
        gpu_count: Number of GPUs. Must be > 1
        """
        super(ParallelModel, self).__init__()
        self.inner_model = keras_model
        self.gpu_count = gpu_count
        merged_outputs = self.make_parallel()
        super(ParallelModel, self).__init__(inputs=self.inner_model.inputs,
                                            outputs=merged_outputs)

The trick works also for me... :smile:
Keras v2.2.4

This solution works with "Keras==2.2.2"

@shen338 You say you ran into the error of requiring input and output, how did you fix this???

Solved by changing code in mrcnn/parallel_model.py as the following:

class ParallelModel(KM.Model):
    def __init__(self, keras_model, gpu_count):
        """Class constructor.
        keras_model: The Keras model to parallelize
        gpu_count: Number of GPUs. Must be > 1
        """
        super(ParallelModel, self).__init__()
        self.inner_model = keras_model
        self.gpu_count = gpu_count
        merged_outputs = self.make_parallel()
        super(ParallelModel, self).__init__(inputs=self.inner_model.inputs,
                                            outputs=merged_outputs)

Thanks, above change accepts multiple GPUs count but getting below error while training on multiple GPU's

Starting at epoch 0. LR=0.001

Checkpoint Path: ../matterport_mask_rcnn/logs/cocosynth_dataset20191125T0544/mask_rcnn_cocosynth_dataset_{epoch:04d}.h5
Selecting layers to train
fpn_c5p5 (Conv2D)
fpn_c4p4 (Conv2D)
fpn_c3p3 (Conv2D)
fpn_c2p2 (Conv2D)
fpn_p5 (Conv2D)
fpn_p2 (Conv2D)
fpn_p3 (Conv2D)
fpn_p4 (Conv2D)
In model: rpn_model
rpn_conv_shared (Conv2D)
rpn_class_raw (Conv2D)
rpn_bbox_pred (Conv2D)
mrcnn_mask_conv1 (TimeDistributed)
mrcnn_mask_bn1 (TimeDistributed)
mrcnn_mask_conv2 (TimeDistributed)
mrcnn_mask_bn2 (TimeDistributed)
mrcnn_class_conv1 (TimeDistributed)
mrcnn_class_bn1 (TimeDistributed)
mrcnn_mask_conv3 (TimeDistributed)
mrcnn_mask_bn3 (TimeDistributed)
mrcnn_class_conv2 (TimeDistributed)
mrcnn_class_bn2 (TimeDistributed)
mrcnn_mask_conv4 (TimeDistributed)
mrcnn_mask_bn4 (TimeDistributed)
mrcnn_bbox_fc (TimeDistributed)
mrcnn_mask_deconv (TimeDistributed)
mrcnn_class_logits (TimeDistributed)

mrcnn_mask (TimeDistributed)

AttributeError Traceback (most recent call last)
in
7 learning_rate=config.LEARNING_RATE,
8 epochs=4,
----> 9 layers='heads')
10 end_train = time.time()
11 minutes = round((end_train - start_train) / 60, 2)

~/objectDetection/matterport_mask_rcnn/mrcnn/model.py in train(self, train_dataset, val_dataset, learning_rate, epochs, layers, augmentation, custom_callbacks, no_augmentation_sources)
2352 log("Checkpoint Path: {}".format(self.checkpoint_path))
2353 self.set_trainable(layers)
-> 2354 self.compile(learning_rate, self.config.LEARNING_MOMENTUM)
2355
2356 # Work-around for Windows: Keras fails on Windows when using

~/objectDetection/matterport_mask_rcnn/mrcnn/model.py in compile(self, learning_rate, momentum)
2197 tf.reduce_mean(layer.output, keepdims=True)
2198 * self.config.LOSS_WEIGHTS.get(name, 1.))
-> 2199 self.keras_model.metrics_tensors.append(loss)
2200
2201 def set_trainable(self, layer_regex, keras_model=None, indent=0, verbose=1):

~/objectDetection/matterport_mask_rcnn/mrcnn/parallel_model.py in __getattribute__(self, attrname)
45 if 'load' in attrname or 'save' in attrname:
46 return getattr(self.inner_model, attrname)
---> 47 return super(ParallelModel, self).__getattribute__(attrname)
48
49 def summary(self, args, *kwargs):

AttributeError: 'ParallelModel' object has no attribute 'metrics_tensors'

Was this page helpful?
0 / 5 - 0 ratings