Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

python - Implementation of ResNet 101 not possible

I am trying to implement ResNet 101 for video classification by following the code from https://gist.github.com/flyyufelix/65018873f8cb2bbe95f429c474aa1294

Tf version - 1.14.0

Input size - 256 frames X 80 X 60 X 1

I am not able to understand how to give inputs to this model and not able to resolve this error:

Image - >

TypeError                                 Traceback (most recent call last)
<ipython-input-147-9d112a71e8b5> in <module>
     10 #cnn = c3d_model(32)
     11 
---> 12 cnn = resnet101_model()
     13 model = cnn

<ipython-input-137-14cd7725e66f> in resnet101_model(weights_path)
     19     x = MaxPooling2D((3, 3), strides=(2, 2), name='pool1')(x)
     20 
---> 21     x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1))
     22     x = identity_block(x, 3, [64, 64, 256], stage=2, block='b')
     23     x = identity_block(x, 3, [64, 64, 256], stage=2, block='c')

<ipython-input-133-bbe3e4d0fcf7> in conv_block(input_tensor, kernel_size, filters, stage, block, strides)
     31 
     32     #x = x.add([x, shortcut], mode='sum', name='res' + str(stage) + block)
---> 33     x = keras.layers.merge.Add([x, shortcut], mode='sum', name='res' + str(stage) + block)
     34     x = Activation('relu', name='res' + str(stage) + block + '_relu')(x)
     35     return x

TypeError: __init__() takes 1 positional argument but 2 were given

[2] After applying the x = keras.layers.merge.Add([x, shortcut]), error is: https://i.stack.imgur.com/gcFRG.png

question from:https://stackoverflow.com/questions/65933290/implementation-of-resnet-101-not-possible

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The error comes from providing an extra argument to a function (init from the class Add here). Those arguments were ok with keras.layers.merge but here you are using keras.layers.merge.Add . Here as we already use the Add class in keras.layers, the argument "mode" might not exist. Can you try again with this line of code instead?

x = keras.layers.Add(name='res' + str(stage) + block)([x, shortcut])

If it is not working for this version of keras and tf maybe this one should work, but you will lose the name of the layer.

x = keras.layers.merge.Add([x, shortcut])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...