keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 910 forks source link

Error of Custom DenseNet layer blocks=[2,2,2,2] #66

Closed qxde01 closed 5 years ago

qxde01 commented 5 years ago
x=Input(shape=(224,224,3))
from keras_applications import densenet
model=densenet.DenseNet(blocks=[2,2,2,2],weights=None,input_tensor=x)

or

from keras.applications import densenet
model=densenet.densenet.DenseNet(blocks=[2,2,2,2],weights=None,input_tensor=x)

Error: Traceback (most recent call last): File "", line 1, in File "D:\Py36\Python36\lib\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'

taehoonlee commented 5 years ago

@qxde01, Thank you for trying Keras. Currently, the function densenet is designed for internal generic function, thus you can't use it directly. If you want to customize the numbers of dense blocks, you can use the following workarounds:

from keras_applications import densenet
from keras.applications import keras_modules_injection

@keras_modules_injection
def yourDenseNet(*args, **kwargs):
    return densenet.DenseNet(*args, **kwargs)

model = yourDenseNet(blocks=[2,2,2,2], weights=None)
qxde01 commented 5 years ago

@taehoonlee thank you. It can be solved as follows:

x=Input(shape=(224,224,3))
model=densenet.DenseNet(blocks=[2,2,2,2],weights=None,input_tensor=x,backend=keras.backend,layers=keras.layers,...)
taehoonlee commented 5 years ago

@qxde01, Yes, that is also possible. Thank you!