weixin_39682697
weixin_39682697
2020-11-28 19:13

ValueError on Python 3.4 environment using TensorFlow backend

I worked well on Python 2.7 environment using Theano backend, but I got a ValueError on Python 3.4 environment using TensorFlow backend. How should I resolve that?


Keiku:~/keras-resnet$ python resnet.py
Using TensorFlow backend.
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally

(Omitted)

Traceback (most recent call last):
  File "resnet.py", line 147, in <module>
    main()
  File "resnet.py", line 127, in main
    model = resnet()
  File "resnet.py", line 111, in resnet
    block2 = _residual_block(block_fn, nb_filters=128, repetations=4)(block1)
  File "resnet.py", line 94, in f
    input = block_function(nb_filters=nb_filters, init_subsample=init_subsample)(input)
  File "resnet.py", line 48, in f
    conv_1_1 = _bn_relu_conv(nb_filters, 1, 1, subsample=init_subsample)(input)
  File "resnet.py", line 38, in f
    init="he_normal", border_mode="same")(activation)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/keras/engine/topology.py", line 485, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/keras/engine/topology.py", line 543, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/keras/engine/topology.py", line 148, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/keras/layers/convolutional.py", line 341, in call
    filter_shape=self.W_shape)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/keras/backend/tensorflow_backend.py", line 952, in conv2d
    x = tf.nn.conv2d(x, kernel, strides, padding=padding)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 295, in conv2d
    data_format=data_format, name=name)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 2156, in create_op
    set_shapes_for_outputs(ret)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 1612, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/tensorflow/python/ops/common_shapes.py", line 238, in conv2d_shape
    in_rows, in_cols, filter_rows, filter_cols, stride_r, stride_c, padding)
  File "/home/Keiku/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/tensorflow/python/ops/common_shapes.py", line 155, in get2d_conv_output_size
    % (row_stride, col_stride, filter_height, filter_width))
ValueError: ('stride must be less than or equal to filter size', 'stride: [2x2] filter: [1x1]')
Keiku:~/keras-resnet$
</module>

该提问来源于开源项目:raghakot/keras-resnet

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39967096 weixin_39967096 5月前

    This is actually a bug in tensorflow: https://github.com/tensorflow/tensorflow/issues/889 It should be fixed in the latest version.

    Try installing the latest with sudo pip3 install --upgrade http://ci.tensorflow.org/view/Nightly/job/nigntly-matrix-linux-gpu/TF_BUILD_CONTAINER_TYPE=GPU,TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON3,label=gpu-working/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl

    点赞 评论 复制链接分享
  • weixin_39967096 weixin_39967096 5月前

    There is still an issue with training during backward pass. It is being tracked here: https://github.com/tensorflow/tensorflow/issues/2066

    点赞 评论 复制链接分享
  • weixin_39967096 weixin_39967096 5月前

    Forward pass works fine with latest nightly

    点赞 评论 复制链接分享
  • weixin_39682697 weixin_39682697 5月前

    Thank you for the detailed explanation, but I am not able to understand all in the detail. For now, it seems to have worked on Python 3.4 using above TensorFlow.

    Note: I executed resnet.py in the my local PC(almost the same environment) because of a private matter, and I commented out plot model code because I wasn't able to install pydot on Python 3.4.

    From now, I'm going to study this program and above TensorFlow problems. Thank you for your support.

    
    ➜  keras-resnet git:(master) ✗ python resnet.py 
    Using TensorFlow backend.
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally
    I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:900] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
    I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 
    name: GeForce GTX 980
    major: 5 minor: 2 memoryClockRate (GHz) 1.2155
    pciBusID 0000:01:00.0
    Total memory: 4.00GiB
    Free memory: 3.43GiB
    I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
    I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y 
    I tensorflow/core/common_runtime/gpu/gpu_device.cc:755] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 980, pci bus id: 0000:01:00.0)
    /home/kuroyanagi/.pyenv/versions/anaconda3-2.3.0/lib/python3.4/site-packages/keras/initializations.py:35: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
      return K.variable(np.random.normal(loc=0.0, scale=scale, size=shape),
    10.858797073364258 s to make model
    3.5762786865234375e-06 s to get output
    1.9988222122192383 s to get compile
    ➜  keras-resnet git:(master) ✗ 
    
    点赞 评论 复制链接分享
  • weixin_39967096 weixin_39967096 5月前

    It is an issue with conv stride > conv kernel size. You would think it makes sense to add this check since we are skipping over data when the kernels slide over the window. They fixed back prop issue. You should be able to do both forward and backward pass now.

    点赞 评论 复制链接分享