Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

keras - “ my_layer”对象没有属性“ _dynamic”('my_layer' object has no attribute '_dynamic')

I want to design a model by tensorflow2.0,when Icompile the model,it report an error

(我想通过tensorflow2.0设计一个模型,当我编译模型时,报告一个错误)

'my_layer' object has no attribute '_dynamic' the code is

(“ my_layer”对象没有属性“ _dynamic”,代码为)

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

class my_layer(layers.Layer):
    def __init__(self,classes):
        self.conv1 = layers.Conv2D(32,(3,3),strides=1,padding='same')
        self.conv2 = layers.Conv2D(64,(3,3),strides=1,padding='same')
        self.conv3 = layers.Conv2D(32, (3, 3), strides=1, padding='same')
        self.conv4 = layers.Conv2D(classes, (3, 3), strides=1, padding='same')
        self.bn = layers.BatchNormalization()
        self.glbavgpool = layers.GlobalMaxPooling2D()
        self.fc = layers.Dense(classes)

    def call(self,inputs):
        x = self.conv1(inputs)
        x = self.bn(x)
        x = keras.activations.relu(x)
        x = self.conv2(x)
        x = keras.activations.relu(x)
        x = self.conv3(x)
        x = self.conv4(x)
        x = self.bn(x)
        x = self.glbavgpool(x)
        out = self.fc(x)
        return out


class mymodel(keras.Model):
    def __init__(self,classes):
        super(mymodel,self).__init__()
        self.ml = my_layer(classes=classes)

    def call(self,inputs):
        return self.ml(inputs)

then I put all the custom layers to my_model, it worked.

(然后我将所有自定义图层放入my_model,它起作用了。)

I think it's probably the wrong way to use mylayer.

(我认为这可能是使用mylayer的错误方法。)

  ask by Mozhenwei translate from so

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

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...