如何在tesorflow_hub中为现有的经过预训练的resnet50模型添加额外的通道?

时间:2019-09-30 19:53:18

标签: tensorflow resnet pre-trained-model tensorflow-hub

我正在尝试使用来自tensorflow_hub的预训练的Resnet50模型。但是,我打算修改第一卷积层以使其能够采用4通道张量(图像+二进制掩码),其中网络权重是根据预先训练的模型初始化的,除了新的 添加了随机初始化的过滤器。

用于提取Resnet50权重的基本代码:

import tensorflow_hub as hub
import numpy as np
module = hub.Module("https://tfhub.dev/google/imagenet/resnet_v1_50/feature_vector/3")
batch = 2
channels = 3
height, width = hub.get_expected_image_size(module)
images = np.zeros((batch, height, width, channels))
features = module(dict(images=images), signature="image_feature_vector", as_dict=True)

1 个答案:

答案 0 :(得分:0)

要像这样修改网络架构,最好直接使用TensorFlow源代码。 TensorFlow的ResNet-50的实现有几种,包括(没有特定的顺序)

有关恢复预训练的检查点的说明,请参见相应的存储库。 (取消集线器模块,您将失去很好的自动化。)