ERROR: Assign requires shapes of both tensors to match. lhs shape= [1001] rhs shape= [10]

利用tensorflow/slim将训练的cifar10分类网络输出为带权重的模型,报错:

ERROR: Assign requires shapes of both tensors to match. lhs shape= [1001] rhs shape= [10]

solution:

slim默认分类网络为ImageNet,因此类别数为1000+1(背景),如果用cifar10训练,需要将类别数修改为10。

在export_inference_graph.py中添加几行代码,修改模型的类别数目即可。蓝色代码为新添加的代码。

tf.app.flags.DEFINE_integer(
    'output_size', 10, 'whether to use cifar10 or not, if use ImageNet, set to 1001.')

FLAGS = tf.app.flags.FLAGS


def main(_):
  if not FLAGS.output_file:
    raise ValueError('You must supply the path to save to with --output_file')
  tf.logging.set_verbosity(tf.logging.INFO)
  with tf.Graph().as_default() as graph:
    dataset = dataset_factory.get_dataset(FLAGS.dataset_name, 'train',
                                          FLAGS.dataset_dir)
    dataset.num_classes = FLAGS.output_size
    network_fn = nets_factory.get_network_fn(
        FLAGS.model_name,
        num_classes=(dataset.num_classes - FLAGS.labels_offset),
        is_training=FLAGS.is_training)

附录:

从ckpt输出为模型官网链接:

  1. https://github.com/tensorflow/models/tree/master/research/slim#exporting-the-inference-graph(在models/research/slim文件夹下输出)
  2. https://github.com/tensorflow/models/tree/master/research/slim#freezing-the-exported-graph (在tensorflow文件夹下bazel)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值