运行模型一部分的最简单方法是什么?

时间:2019-04-08 08:22:30

标签: tensorflow keras

我正在处理Keras功能API。 专门针对我的实验,我使用的Keras resnet50模型是通过以下方式获得的:

class AmazonProductSpider(scrapy.Spider):
    name = "AmazonDeals"
    allowed_domains = ["amazon.com"]
    start_urls = ["https://www.amazon.com/s?k=trimmer&ref=nb_sb_noss_2"]
    custom_settings = {
            'FEED_URI' : 'Asin_Titles.json',
            'FEED_FORMAT' : 'json'
    }

很显然,要获得网络的最终输出,我们需要将一个值提供给占位符model = resnet50.ResNet50(weights='imagenet')

我的问题是,如果我将适当尺寸的值输入其中,我是否可以从下图底部所示的input_1层开始推断该图?

我试图通过Keras relu实现这一目标。像这样:

functions

但是这种方法行不通,因为再次推断出我需要将值输入张量的任何输出。

在这里重新创建图形是我的最佳选择吗?

谢谢

The input of the network is input_1. The layer of interest is Relu at the bottom

1 个答案:

答案 0 :(得分:0)

如果我说对了,您可以只指定输入和输出节点

base_model = tf.keras.applications.ResNet50(weights='imagenet')
inference_model = tf.keras.Model(inputs=base_model.input, outputs=base_model.get_layer('any_layer_name').output)

您可以将输出设置为任何图层名称