在张量流中转移学习

时间:2019-07-10 02:50:35

标签: python tensorflow keras transfer-learning

我想从预先训练的MobileNet转移权重。预训练是在Image net上完成的,我只需要传递特征图(而不是网络的头部)。以下过程通过keras中的链接(在该平台中加载了模型)来说明。

https://www.tensorflow.org/tutorials/images/transfer_learning

不幸的是,我的模型处于张量流中,而不是顺序的keras:

def model(imagesize):
   with tf.variable_scope('init_conv'):
        output = tc.layers.conv2d(self.input, 32, 3, 2,
                                      normalizer_fn=self.normalizer, 
                                    normalizer_params=self.bn_params)
        self.output = self._inverted_bottleneck(output, 1, 16, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 24, 1)  
        self.output = self._inverted_bottleneck(self.output, 6, 24, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 32, 1)
        self.output = self._inverted_bottleneck(self.output, 6, 32, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 32, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 64, 1)
        self.output = self._inverted_bottleneck(self.output, 6, 64, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 64, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 64, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 96, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 96, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 96, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 160, 1)
        self.output = self._inverted_bottleneck(self.output, 6, 160, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 160, 0)
        self.output = self._inverted_bottleneck(self.output, 6, 320, 0)
        self.output = tc.layers.conv2d(self.output, 1280, 1, 
        activation_fn=tf.nn.relu6, normalizer_fn=self.normalizer,
                                       normalizer_params=self.bn_params)
   return self.output

我的问题是: 1-我如何进行转学? 2-我可以加载我的预训练模型并冻结某些图层并在tf中更改网络的头部吗?

0 个答案:

没有答案