flyyufelix / DenseNet-Keras

DenseNet Implementation in Keras with ImageNet Pretrained Models
MIT License
566 stars 264 forks source link

TypeError: 'module' object is not callable #22

Closed Digital2Slave closed 5 years ago

Digital2Slave commented 5 years ago

Version

DenseNet-Keras git:(master) ipython
Python 2.7.12 (default, Dec  4 2017, 14:50:18)
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import cv2

In [2]: import tensorflow as tf

In [3]: cv2.__version__
Out[3]: '2.4.13.6'

In [4]: tf.__version__
Out[4]: '1.4.0'

In [5]: import keras
Using TensorFlow backend.

In [6]: keras.__version__
Out[6]: '2.2.2'

DenseNet-Keras git:(master) ls -hl imagenet_models
total 33M
drwxrwxr-x 2 epbox epbox 4.0K 8月  30 15:08 .
drwxrwxr-x 5 epbox epbox 4.0K 8月  30 15:09 ..
-rw-r--r-- 1 epbox epbox  32M 8月  30 15:07 densenet121_weights_tf.h5
-rw-rw-r-- 1 epbox epbox   55 8月  30 14:40 README.md

Error

DenseNet-Keras git:(master) python test_inference.py
Using TensorFlow backend.
/home/epbox/Github/DenseNet-Keras/densenet121.py:45: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (7, 7), strides=(2, 2), use_bias=False, name="conv1")`
  x = Convolution2D(nb_filter, 7, 7, subsample=(2, 2), name='conv1', bias=False)(x)
2018-09-10 14:25:19.720132: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-09-10 14:25:19.821988: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-09-10 14:25:19.822306: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GTX TITAN X major: 5 minor: 2 memoryClockRate(GHz): 1.076
pciBusID: 0000:01:00.0
totalMemory: 11.92GiB freeMemory: 11.64GiB
2018-09-10 14:25:19.822322: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:01:00.0, compute capability: 5.2)
/home/epbox/Github/DenseNet-Keras/densenet121.py:99: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(128, (1, 1), use_bias=False, name="conv2_1_x1")`
  x = Convolution2D(inter_channel, 1, 1, name=conv_name_base+'_x1', bias=False)(x)
/home/epbox/Github/DenseNet-Keras/densenet121.py:109: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(32, (3, 3), use_bias=False, name="conv2_1_x2")`
  x = Convolution2D(nb_filter, 3, 3, name=conv_name_base+'_x2', bias=False)(x)
Traceback (most recent call last):
  File "test_inference.py", line 34, in <module>
    model = DenseNet(reduction=0.5, classes=1000, weights_path=weights_path)
  File "/home/epbox/Github/DenseNet-Keras/densenet121.py", line 55, in DenseNet
    x, nb_filter = dense_block(x, stage, nb_layers[block_idx], nb_filter, growth_rate, dropout_rate=dropout_rate, weight_decay=weight_decay)
  File "/home/epbox/Github/DenseNet-Keras/densenet121.py", line 165, in dense_block
    concat_feat = merge([concat_feat, x], mode='concat', concat_axis=concat_axis, name='concat_'+str(stage)+'_'+str(branch))
TypeError: 'module' object is not callable
monder0116 commented 5 years ago

i have same problem ++

django-kz commented 5 years ago

Guys @monder0116, @JohnTian Hi ! I encountered the same problem, I found a solution, but I am not sure that it is 100% correct. So what I did: `from keras.layers import concatenate concat_feat = concatenate([concat_feat, x], mode='concat', axis=concataxis, name='concat'+str(stage)+'_'+str(branch))

I replaced this line withmergetoconcatenate, becausemerge` seems to be deprecated invocation.

YingXiuHe commented 5 years ago

i solved this problem via reinstalled the Keras to 2.0.5 version.

Digital2Slave commented 5 years ago

@django-kz Thanks for sharing.

2018daofeng commented 5 years ago

@YingXiuHe Thanks for sharing.

2018daofeng commented 5 years ago

、、、 from keras.layers import concatenate concat_feat = concatenate([concat_feat, x], axis=concataxis, name='concat'+str(stage)+'_'+str(branch)) 、、、 in my win10,it works. But 、、、 from keras.layers import concatenate concat_feat = concatenate([concat_feat, x], mode='concat', axis=concataxis, name='concat'+str(stage)+'_'+str(branch)) 、、、 it don't work. I guess that is the version problem of keras. Mine:2.2.4

bitscott1102 commented 4 years ago

The latest version of Keras does not support concatenate

Use this Lambda

policy = Lambda(lambda x: x[0]-K.mean(x[0])+x[1], (NUM_ACTIONS,))([advantage, value])

huyanfei-cqupt commented 4 years ago

The latest version of Keras does not support concatenate

Use this Lambda

policy = Lambda(lambda x: x[0]-K.mean(x[0])+x[1], (NUM_ACTIONS,))([advantage, value])

hi, how to write the code? thanks.

bitscott1102 commented 4 years ago

The latest version of Keras does not support concatenate Use this Lambda policy = Lambda(lambda x: x[0]-K.mean(x[0])+x[1], (NUM_ACTIONS,))([advantage, value])

hi, how to write the code? thanks.

Replace concatenate([concat_feat, x], mode='concat', axis=concat_axis, name='concat'+str(stage)+'_'+str(branch))

with policy = Lambda(lambda x: x[0]-K.mean(x[0])+x[1], (NUM_ACTIONS,))([advantage, value])(This is my code. ) https://www.tensorflow.org/api_docs/python/tf/keras/layers/Lambda