Keras-retinanet: Problem to train densenet and mobilenet models

Created on 5 Oct 2018  路  8Comments  路  Source: fizyr/keras-retinanet

When I use any model of resnet or vgg I have no problem, but when I try to test the densenet or mobilenet models the following problems arise:

keras-retinanet/keras_retinanet/bin/train.py --backbone=densenet201 --epochs=1 --steps=1 --no-weights coco /home/manuelvazquezenriquez2/keras-retinanet-test-data/coco

loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Creating model, this may take a second...
Traceback (most recent call last):
  File "keras-retinanet/keras_retinanet/bin/train.py", line 493, in <module>
    main()
  File "keras-retinanet/keras_retinanet/bin/train.py", line 461, in main
    config=args.config
  File "keras-retinanet/keras_retinanet/bin/train.py", line 118, in create_models
    model          = model_with_weights(backbone_retinanet(num_classes, num_anchors=num_anchors, modifier=modifier), weights=weights, skip_mismatch=True)
  File "keras-retinanet/keras_retinanet/bin/../../keras_retinanet/models/densenet.py", line 35, in retinanet
    return densenet_retinanet(*args, backbone=self.backbone, **kwargs)
  File "keras-retinanet/keras_retinanet/bin/../../keras_retinanet/models/densenet.py", line 85, in densenet_retinanet
    backbone = densenet.DenseNet(blocks=blocks, input_tensor=inputs, include_top=False, pooling=None, weights=None)
  File "/home/manuelvazquezenriquez2/.local/lib/python2.7/site-packages/keras_applications/densenet.py", line 193, in DenseNet
    data_format=backend.image_data_format(),
AttributeError: 'NoneType' object has no attribute 'image_data_format'

keras-retinanet/keras_retinanet/bin/train.py --backbone=mobilenet128 --epochs=1 --steps=1 --no-weights coco /home/manuelvazquezenriquez2/keras-retinanet-test-data/coco

loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Creating model, this may take a second...
Traceback (most recent call last):
  File "keras-retinanet/keras_retinanet/bin/train.py", line 493, in <module>
    main()
  File "keras-retinanet/keras_retinanet/bin/train.py", line 461, in main
    config=args.config
  File "keras-retinanet/keras_retinanet/bin/train.py", line 118, in create_models
    model          = model_with_weights(backbone_retinanet(num_classes, num_anchors=num_anchors, modifier=modifier), weights=weights, skip_mismatch=True)
  File "keras-retinanet/keras_retinanet/bin/../../keras_retinanet/models/mobilenet.py", line 35, in retinanet
    return mobilenet_retinanet(*args, backbone=self.backbone, **kwargs)
  File "keras-retinanet/keras_retinanet/bin/../../keras_retinanet/models/mobilenet.py", line 92, in mobilenet_retinanet
    alpha = float(backbone.split('_')[1])
IndexError: list index out of range

Any idea why it can be?
Thanks

Most helpful comment

On second look, the error of mobilenet is because you're missing the alpha in the backbone name.

It should be --backbone=mobilenet128_1.0 for an alpha of 1.0.

As for densenet, my original question still stands.

All 8 comments

What Keras version are you using? If you're not using 2.2.2, you could try that. I've yet to update support for 2.2.4, I think something broke there.

On second look, the error of mobilenet is because you're missing the alpha in the backbone name.

It should be --backbone=mobilenet128_1.0 for an alpha of 1.0.

As for densenet, my original question still stands.

With the correct version of Keras (v2.2.2) it has worked.
Thank you

So, if I understand correctly, retinanet does not work yet with keras 2.2.4 ?
Because i need to update my keras to use new parametres for another neural network but i must be sure that retinanet still work with keras 2.2.4

Same problem here with DenseNet and keras 2.2.4. Trying to run

base_model = DenseNet(blocks=[6, 12, 24, 16], include_top=False, weights=None, input_shape=(401, 401, 3),
                              pooling='avg')

gives the error

Traceback (most recent call last):
  File "<input>", line 7, in <module>
  File "~/.conda/envs/cytometer_tensorflow_latest/lib/python3.6/site-packages/keras_applications/densenet.py", line 193, in DenseNet
    data_format=backend.image_data_format(),
AttributeError: 'NoneType' object has no attribute 'image_data_format'

Could you try updating keras-retinanet? I think I fixed that issue not so long ago. https://github.com/fizyr/keras-retinanet/commit/dca2d0d777a3a9daec5b2e98bcf76516eebe8887

@hgaiser Sorry, I was trying to use just DenseNet, and ended up here by mistake.

from keras_applications.densenet import DenseNet

Same problem here with DenseNet and keras 2.3.1. Trying to run
model = keras.applications.densenet.densenet.DenseNet(blocks=[6,10,14,12],include_top=False, weights='imagenet', input_tensor=None, input_shape=input_shape, pooling='max', classes=1000,backend=keras.backend,layers=keras.layers)

Was this page helpful?
0 / 5 - 0 ratings