-
深度学习具有强大的特征表达能力。有时候我们训练好分类模型,并不想用来进行分类,而是用来提取特征用于其他任务,比如相似图片计算。接下来讲下如何使用TensorFlow提取特征。
1.必须在模型中命名好要提取的那一层,如下
self.h_pool_flat = tf.reshape(self.h_pool, [-1, num_filters_total], name='h_pool_flat')
2.通过调用sess.run()来获取h_pool_flat层特征
feature = graph.get_operation_by_name("h_pool_flat").outputs[0] batch_predictions, batch_feature = \ sess.run([predictions, feature], {input_x: x_test_batch, dropout_keep_prob: 1.0})
TensorFlow 抽取某一层特征
最新推荐文章于 2022-10-17 21:22:14 发布