大佬教程收集整理的这篇文章主要介绍了带有预训练 resnet50 的中间层误差张量流,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 resnet50 进行迁移学习,但不明白为什么它会给我一个错误。我尝试用 Mobilenet 做同样的事情并且它有效。我使用的电脑没有连接到互联网,因此我单独下载了权重。 这是我的代码
def resnet50(image_size,num_classes,num_chAnnels,dense_size,drop_prec,include_top,preweights):
if preweights:
if include_top:
path = os.path.join('weights_pre_trianed','resnet50_weights_tf_dim_ordering_tf_kernels.h5')
res = applications.resnet50(include_top=include_top,input_shape=(image_size[0],image_size[1],num_chAnnels),weights=path)
x = res.output
preds = Dense(num_classes,activation='softmax')(X)
model = Model(inputs=res.input,outputs=preds)
for layer in model.layers[:143]:
layer.Trainable = false
for layer in model.layers[143:]:
layer.Trainable = True
return model
我收到以下错误
tensorflow.python.framework.errors_impl.InvalIDArgumentError: 2 root error(s) found.
(0) InvalID argument: Computed output size would be negative: -227 [input_size: 56,effective_filter_size: 512,StriDe: 2]
[[{{node res3a_branch1/convolution}}]]
[[Mean/_2259]]
(1) InvalID argument: Computed output size would be negative: -227 [input_size: 56,StriDe: 2]
[[{{node res3a_branch1/convolution}}]]
0 successful operations.
0 derived errors ignored.
我使用 tensorflow 1.15 和 keras 2.3.1。 我的图像是灰度和大小 224x224 a 3 通道 为什么我会收到这个错误?
EDIT1:节点 res3a_branch1 是层号 45 Conv2D EDIT2:我想要一个二元分类
Edit3:我按照链接的建议进行了尝试,但现在出现了与模型相关的另一个错误。我知道@R_683_10675@用 lambda 层,但我不知道如何使用。
'node = layer._inbound_nodes[node_index]
AttributeError: 'nonetype' object has no attribute '_inbound_nodes'
这是我之后的代码
path=os.path.join('weights_pre_trianed','resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5')
i = input([None,None,3],dtype='float32')
x = applications.resnet50.preprocess_input(i)
res = applications.resnet50(include_top=include_top,weights=path)
x = res(X)
x = GlobalAveragePooling2D()(X)
preds = Dense(num_classes,activation='softmax')(X)
model = Model(inputs=i,outputs=preds)
for layer in model.layers[:-2]:
layer.Trainable = false
return model
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的带有预训练 resnet50 的中间层误差张量流全部内容,希望文章能够帮你解决带有预训练 resnet50 的中间层误差张量流所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。