tensorflow微调模型,如何中断梯度

  • import tensorflow as tf
  • # Load the VGG-16 model in the default graph
  • vgg_saver = tf.train.import_meta_graph(dir + '/vgg/results/vgg-16.meta')
  • # Access the graph
  • vgg_graph = tf.get_default_graph()
  • # Retrieve VGG inputs
    self.x_plh = vgg_graph.get_tensor_by_name('input:0')
    # Choose which node you want to connect your own graph
    output_conv =vgg_graph.get_tensor_by_name('conv1_2:0')
    # output_conv =vgg_graph.get_tensor_by_name('conv2_2:0')
    # output_conv =vgg_graph.get_tensor_by_name('conv3_3:0')
  • # output_conv =vgg_graph.get_tensor_by_name('conv4_3:0')
  • # output_conv =vgg_graph.get_tensor_by_name('conv5_3:0')
  • # Stop the gradient for fine-tuning
  • output_conv_sg = tf.stop_gradient(output_conv) # It's an identity functio
  • # Build further operations
  • output_conv_shape = output_conv_sg.get_shape().as_list()
  • W1 = tf.get_variable('W1', shape=[1, 1, output_conv_shape[3], 32], initializer=tf.random_normal_initializer(stddev=1e-1))
  • b1 = tf.get_variable('b1', shape=[32], initializer=tf.constant_initializer(0.1))
  • z1 = tf.nn.conv2d(output_conv_sg, W1, strides=[1, 1, 1, 1], padding='SAME') + b1
  • a = tf.nn.relu(z1)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值