Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Is there ResNet-101 pretrained imagenet weights.h5 #725

Open
engineer1109 opened this issue Jun 27, 2018 · 20 comments
Open

Is there ResNet-101 pretrained imagenet weights.h5 #725

engineer1109 opened this issue Jun 27, 2018 · 20 comments

Comments

@engineer1109
Copy link

only resNet -50?

@mekomlusa
Copy link

Try this.

@engineer1109
Copy link
Author

@mekomlusa Can't link

@mekomlusa
Copy link

@engineer1109 Try this. I remember @flyyufelix put his pre-trained ImageNet weights somewhere on Google Drive, but can't recall it right off my head.

@YubinXie
Copy link

YubinXie commented Jul 4, 2018

Wait, I thought given init_with = "imagnet" # imagenet, coco, or last in the demo means, there are res50, res101 pre-trained weight for both coco and imagenet with this repo. No?

@talhasaruhan
Copy link

I think model just uses resnet50 weights for resnet101 model whereever possible and randomly initializes rest of the layers.

@mekomlusa
Copy link

@talhasaruhan is right. At least I know that ImageNet weight is resnet50 only. See the snapshot below (find more in the source code).

def get_imagenet_weights(self):
        """Downloads ImageNet trained weights from Keras.
        Returns path to weights file.
        """
        from keras.utils.data_utils import get_file
        TF_WEIGHTS_PATH_NO_TOP = 'https://github.com/fchollet/deep-learning-models/'\
                                 'releases/download/v0.2/'\
                                 'resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'
        weights_path = get_file('resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5',
                                TF_WEIGHTS_PATH_NO_TOP,
                                cache_subdir='models',
                                md5_hash='a268eb855778b3df3c7506639542a6af')
        return weights_path

@Paulito-7
Copy link

Paulito-7 commented Jul 5, 2018

Hi everyone,
Have you tried to use ResNet-101 weights for fine tuning your network? Did you get better results than other solutions?

Thank you!

@ppwwyyxx
Copy link

ppwwyyxx commented Jul 5, 2018

@Paulito-7 someone has: #1 (comment)

@talhasaruhan
Copy link

@Paulito-7 I tried that and results weren't much different, although it depends on your training schedule (do you train all the network from epoch 0 or do you train heads for a couple of decades then train the complete network) As always YMMV

@engineer1109
Copy link
Author

@talhasaruhan How do you train the network? My AP is awful.
I train the model all from epoch 0 to 100, learning rate =0.001
Then train the model all from epoch 100 to 150, learning rate =0.0001
Then train the model all from epoch 150 to 200, learning rate =0.00001

@talhasaruhan
Copy link

@engineer1109 I tried training with constant 0.001 for about 200 epochs and starting from 0.002 w/ reduceLrOnPlateau with factor 0.5, at first both training and validation losses were quite above the model with default resnet50 weights. But it started to converge to the same line near the end.

@engineer1109
Copy link
Author

@talhasaruhan weight_decay=0.002?

@talhasaruhan
Copy link

@engineer1109 nope, I had two different runs, one with lr constant 0.00,1 one with lr starting from 0.002 & ReduceLROnPlateau callback. (factor 0.5 patience 20)

@slothkong
Copy link

slothkong commented Sep 20, 2018

@talhasaruhan Could you please explain a bit what gives you the idea and how this would work ?

I found an if-statement that checks for the backbone name when building the model:

Mask_RCNN/mrcnn/model.py

Lines 195 to 203 in 41e7c59

block_count = {"resnet50": 5, "resnet101": 22}[architecture]
for i in range(block_count):
x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i), train_bn=train_bn)
C4 = x
# Stage 5
if stage5:
x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a', train_bn=train_bn)
x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b', train_bn=train_bn)
C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c', train_bn=train_bn)

That would imply that the model is created entirely with some kind of randomly initialized weights and later the pre-trained weights are loaded in:

# Load weights
print("Loading weights ", model_path)
model.load_weights(model_path, by_name=True)

But if this is correct, the first stage of the training would go bad l, since the last layers of resnet101 are not trained, their output would be noise fed into the RoI predictor that follow. Not that only the heads are re-trained in the first 40 epochs, not the imagenet backbone weights:

# Training - Stage 1
print("Training network heads")
model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=40,
layers='heads',
augmentation=augmentation)

any idea on what is really happening with the BACKBONE=resnet101 but resnet50-imagenet weights are downloaded? @waleedka senpai?

@Mhaiyang
Copy link

Mhaiyang commented Mar 6, 2019

@zhuchen115
Copy link

Keras application have a resnet weights https://github.com/keras-team/keras-applications/releases/tag/resnet

@nyck33
Copy link

nyck33 commented Jun 4, 2019

@Mhaiyang @zhuchen115 I keep getting Value Error

ValueError                                Traceback (most recent call last)
<ipython-input-9-e5c3a80cd965> in <module>()
      5     WEIGHTS_DIR = "resnet101_weights_tf.h5"
      6     IMAGENET_DIR = os.path.join(ROOT_DIR, WEIGHTS_DIR)
----> 7     model.load_weights(IMAGENET_DIR)
      8 elif init_with == "coco":
      9     # Load weights trained on MS COCO, but skip layers that

1 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py in load_weights_from_hdf5_group(f, layers, reshape)
   1028                          'containing ' + str(len(layer_names)) +
   1029                          ' layers into a model with ' +
-> 1030                          str(len(filtered_layers)) + ' layers.')
   1031 
   1032     # We batch weight value assignments in a single backend call

ValueError: You are trying to load a weight file containing 304 layers into a model with 233 layers.

and

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-99a1663bd5c4> in <module>()
      5     WEIGHTS_DIR = "resnet101_weights_tf_dim_ordering_tf_kernels_notop.h5"
      6     IMAGENET_DIR = os.path.join(ROOT_DIR, WEIGHTS_DIR)
----> 7     model.load_weights(IMAGENET_DIR)
      8 elif init_with == "coco":
      9     # Load weights trained on MS COCO, but skip layers that

1 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py in load_weights_from_hdf5_group(f, layers, reshape)
   1028                          'containing ' + str(len(layer_names)) +
   1029                          ' layers into a model with ' +
-> 1030                          str(len(filtered_layers)) + ' layers.')
   1031 
   1032     # We batch weight value assignments in a single backend call

ValueError: You are trying to load a weight file containing 208 layers into a model with 233 layers.

@zhuchen115
Copy link

@nyck33
Try to use

model.load_weights(IMAGENET_DIR, by_name=True)

@ghost
Copy link

ghost commented Mar 22, 2021

Keras application have a resnet weights https://github.com/keras-team/keras-applications/releases/tag/resnet

I used these with resnet101 architecture, and am somehow getting higher losses than when I used resnet50 weights!

@Dickoabc123
Copy link

are these resnet-101 weights trained on imagenet ?
https://github.com/keras-team/keras-applications/releases/tag/resnet

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests