gpt4 book ai didi

python - 构建 CNN 模型但遇到 'Tensor-typed variable initializers must either be wrapped in an init_scope or callable'

转载 作者:行者123 更新时间:2023-12-04 17:19:13 24 4
gpt4 key购买 nike

我想在构建 CNN 模型时使用 he_normal 作为内核初始化器,但是遇到这个错误代码并且找不到解决方案。有什么建议吗?尽我所能搜索但仍然无法解决此问题。任何建议将不胜感激!

initializer=initializers.he_uniform()
initializer

model = Sequential()
# 1st layer:convolution
#input size:pixel*channel=(224*224)*3
#output size:pixel*filter_num=(224*224)*32
#parameter:kernel size*channel*filter_num=(3*3)*3*32+32
model.add(Conv2D(32, (3, 3), padding='same',input_shape=X_train.shape[1:]))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dropout(0.25))

# 2nd layer:convolution + pooling
model.add(Conv2D(32, (3, 3),kernel_initializer=initializer))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

# 3rd layer:convolution + pooling
model.add(Conv2D(64, (3, 3), padding='same',kernel_initializer=initializer))
model.add(BatchNormalization())
model.add(Activation('relu'))

# 4th layer:convolution + pooling
model.add(Conv2D(64, (3, 3),kernel_initializer=initializer))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

# 5th layer -covolution + pooling
model.add(Conv2D(128, (3, 3),kernel_initializer=initializer))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

# 6th~8th layer(MLP) : flatten(FC) + hidden(512) + output(15)
model.add(Flatten())
model.add(Dense(512))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Dense(numclass))
model.add(Activation('softmax'))
model.summary()

最佳答案

kernel_initializer='he_uniform'

这应该可行

关于python - 构建 CNN 模型但遇到 'Tensor-typed variable initializers must either be wrapped in an init_scope or callable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67244453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com