使用苗条模型库训练网络时出错:TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是'Tensor'

时间:2019-09-10 10:25:19

标签: tensorflow tensorflow-slim

我试图在tensorflow / models / research / slim / net中添加一个简单的网络以使用训练代码对其进行训练,当我尝试在resnet中向其发送功能图时遇到了这个问题。

发送到其中的要素图如下:

Tensor("resnet_v1_152/block1/unit_3/bottleneck_v1/Relu:0", shape=(16, 28, 28, 256), dtype=float32)

这是从网络返回的端点得出的。

我尝试使用占位符替换批处理队列,并且仍然出现相同的错误,我不知道问题出在哪里。

以下是网络体系结构的代码。


def dis_conv(inputs,
             scope='dis_conv',
             is_training=True,
             reuse=tf.AUTO_REUSE):
    with tf.variable_scope(scope, 'dis_conv', [inputs], reuse=reuse) as sc:
        end_points_collection = sc.original_name_scope + '_end_points'
        with slim.arg_scope([slim.conv2d],
                            activation_fn=tf.nn.relu,
                            outputs_collections=end_points_collection,
                            reuse=tf.AUTO_REUSE,
                            ):
            with (slim.arg_scope([slim.batch_norm], is_training=is_training)):
                depth = tf.shape(inputs)[-1]
                width = tf.shape(inputs)[-2]
                net = slim.conv2d(inputs, depth * 2, 3, stride=2, padding='SAME', scope='conv_1')
                net = slim.conv2d(net, depth * 4, 3, stride=2, padding='SAME', scope='conv_2')
                net = slim.conv2d(net, depth * 8, 3, stride=1, padding='SAME', scope='conv_3')
                net = slim.conv2d(net, 1, width / 4, stride=1, padding='SAME', scope='conv_4')
                net = tf.squeeze(net)
                end_points = slim.utils.convert_collection_to_dict(end_points_collection)
                end_points[sc.name + '/conv_4'] = net
                return net, end_points

Traceback (most recent call last):
  File "nonslim_act_GAN_distilling_train_eval.py", line 869, in <module>
    tf.app.run()
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "nonslim_act_GAN_distilling_train_eval.py", line 731, in main
    resT = [dis(EPT[0])[0], dis(EPT[1])[0],
  File "/media/disk/Backup/02zhaofeng/Distalling_inceptionV3/nets/discriminator.py", line 59, in dis_conv
    net = slim.conv2d(inputs, depth * 2, 3, stride=2, padding='SAME', scope='conv_1')
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 183, in func_with_args
    return func(*args, **current_args)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1154, in convolution2d
    conv_dims=2)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 183, in func_with_args
    return func(*args, **current_args)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1057, in convolution
    outputs = layer.apply(inputs)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 805, in apply
    return self.__call__(inputs, *args, **kwargs)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 362, in __call__
    outputs = super(Layer, self).__call__(inputs, *args, **kwargs)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 728, in __call__
    self.build(input_shapes)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/keras/layers/convolutional.py", line 161, in build
    dtype=self.dtype)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 276, in add_weight
    getter=vs.get_variable)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 565, in add_weight
    aggregation=aggregation)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/training/checkpointable/base.py", line 535, in _add_variable_with_custom_getter
    **kwargs_for_getter)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 1467, in get_variable
    aggregation=aggregation)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 1217, in get_variable
    aggregation=aggregation)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 510, in get_variable
    return custom_getter(**custom_getter_kwargs)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1744, in layer_variable_getter
    return _model_variable_getter(getter, *args, **kwargs)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1735, in _model_variable_getter
    use_resource=use_resource)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 183, in func_with_args
    return func(*args, **current_args)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 297, in model_variable
    use_resource=use_resource)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 183, in func_with_args
    return func(*args, **current_args)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 252, in variable
    use_resource=use_resource)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 481, in _true_getter
    aggregation=aggregation)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 836, in _get_single_variable
    shape = tensor_shape.as_shape(shape)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 946, in as_shape
    return TensorShape(shape)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 541, in __init__
    self._dims = [as_dimension(d) for d in dims_iter]
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 541, in <listcomp>
    self._dims = [as_dimension(d) for d in dims_iter]
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 482, in as_dimension
    return Dimension(value)
  File "/media/disk/Backup/02zhaofeng/anaconda3/envs/envPyTF/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 37, in __init__
    self._value = int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'

0 个答案:

没有答案