Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cifar10_input.py calls tf.strided_slice() with 3 arguments, 4 needed. #817

Closed
dweekly opened this issue Dec 26, 2016 · 20 comments
Closed

cifar10_input.py calls tf.strided_slice() with 3 arguments, 4 needed. #817

dweekly opened this issue Dec 26, 2016 · 20 comments
Labels
type:bug Bug in the code

Comments

@dweekly
Copy link
Contributor

dweekly commented Dec 26, 2016

Please let us know which model this issue is about (specify the top-level directory)

models/tutorials/image/cifar10/cifar10_input.py:87

File "/mnt/st12tb/models/tutorials/image/cifar10/cifar10_input.py", line 87, in read_cifar10
tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)

models/tutorials/image/cifar10/cifar10_input.py:93

File "/mnt/st12tb/models/tutorials/image/cifar10/cifar10_input.py", line 93, in read_cifar10
[label_bytes + image_bytes]),

In both cases, running the script, e.g. with "python cifar10_train.py" on TensorFlow v0.12 yields

TypeError: strided_slice() takes at least 4 arguments (3 given)

@bobbyAtSperry
Copy link

I am having the same problem. See my description here on stackoverflow.

@szy1900
Copy link

szy1900 commented Dec 28, 2016

I have the same problem

@debajyotidatta
Copy link

This problem also happens while running, ptb_word_lm.py.

Version of tensorflow : '0.12.0'

Entire traceback:


TypeError Traceback (most recent call last)
in ()
6
7 with tf.name_scope("Train"):
----> 8 train_input = PTBInput(config=config, data=train_data, name="TrainInput")
9 with tf.variable_scope("Model", reuse=None, initializer=initializer):
10 m = PTBModel(is_training=True, config=config, input_=train_input)

in init(self, config, data, name)
92 self.epoch_size = ((len(data) // batch_size) - 1) // num_steps
93 self.input_data, self.targets = reader.ptb_producer(
---> 94 data, batch_size, num_steps, name=name)
95
96

/home/ubuntu/Dropbox/xai/Machine175/AttentionModels/rnn/ptb/reader.pyc in ptb_producer(raw_data, batch_size, num_steps, name)
115 i = tf.train.range_input_producer(epoch_size, shuffle=False).dequeue()
116 x = tf.strided_slice(data, [0, i * num_steps],
--> 117 [batch_size, (i + 1) * num_steps])
118 x.set_shape([batch_size, num_steps])
119 y = tf.strided_slice(data, [0, i * num_steps + 1],

TypeError: strided_slice() takes at least 4 arguments (3 given)

@Cuongvn08
Copy link

Cuongvn08 commented Dec 29, 2016

I used slice() instead of strided_slice(), It was working.
However, another error occurred when I ran cifar10_train.py.
... cifar10/cifar10_input.py", line 135, in _generate_image_and_label_batch tf.contrib.deprecated.image_summary('images', images)
AttributeError: 'module' object has no attribute 'deprecated'

Is there any recommendation for this issue?
Thank you.

@Cuongvn08
Copy link

I have found out the solution for my issue above.
Solution: I modified to use tf.summary instead of tf.contrib.deprecated :). And It worked well.

@bobbyAtSperry
Copy link

After looking at @Cuongvn08 I have put the following changes in which seem to make it work:

In cifar10_input.py

-  result.label = tf.cast(tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)
+  result.label = tf.cast(tf.slice(record_bytes, [0], [label_bytes]), tf.int32)
-  depth_major = tf.reshape( tf.strided_slice(record_bytes, [label_bytes], [label_bytes + image_bytes]),      [result.depth, result.height, result.width])
+  depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]), [result.depth, result.height, result.width])

Then in both cifar10_input.py and cifar10.py I had to search for "deprecated" and wherever I found it, replace it with a valid function based on what I read in the api guide (hopefully correctly). Examples of this:

-  tf.contrib.deprecated.image_summary('images', images)
+  tf.summary.image('images', images)

and

 - tf.contrib.deprecated.histogram_summary(tensor_name + '/activations', x)
 - tf.contrib.deprecated.scalar_summary(tensor_name + '/sparsity',
 + tf.summary.histogram(tensor_name + '/activations', x)
 + tf.summary.scalar(tensor_name + '/sparsity',

It seems to be chugging along happily now. I'll see if it completes OK and if the changes I put in above give the desired diagnostic outputs.

I'd still like to hear a definitive answer from someone closer to the code.

@mfclarke
Copy link

mfclarke commented Dec 29, 2016

@debajyotidatta looks like #824 fixes the problem - runs fine for me with those changes

@piatra
Copy link

piatra commented Dec 29, 2016

Does anyone know a more extensive documentation for strided_slice? I don't understand what the 4th argument should look like. The only one I seem to come across is https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/api_docs/python/functions_and_classes/shard8/tf.strided_slice.md

@chsahit
Copy link

chsahit commented Dec 29, 2016

@piatra this page is fairly helpful:
https://www.tensorflow.org/api_docs/python/array_ops/slicing_and_joining
You have to scroll down a bit to get to the strided slice.

@SamuelMarks
Copy link
Contributor

SamuelMarks commented Dec 31, 2016

Automating the changes required (with GNU sed and perl 5.22.2):

$ find tensorflow/models/tutorials/image/cifar10 -type f -name '*.py' -exec sed -i 's/tf.contrib.deprecated/tf.summary/g' {} \; -exec perl -p -i -e 's/(tf.strided_slice.*?\))/\1, [1,1])/' {} \;

@piatra - the answer from #824 is to add a 4th [needed argument] of [1, 1] to strided_slice.

@bobbyAtSperry
Copy link

bobbyAtSperry commented Jan 1, 2017 via email

@mianmian3
Copy link

did you resolve this problem? I also encountered the same problem.

@mianmian3
Copy link

@bobbyAtSperry , ValueError: Cannot reshape a tensor with 3073 elements to shape [3,32,32] (3072 elements) for 'Reshape' (op: 'Reshape') with input shapes: [3073], [3].
did you resolve this problem?

@bobbyAtSperry
Copy link

@mianmian3 Yes. See my reply further up the chain or summarised in the answer here. The specific line to fix this is
depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]), [result.depth, result.height, result.width])
Note that slice takes differnt arguments. Start and Length rather than Start and End hence the error.

There is an alternative comprehensive answer to this question here, but you have to use the reply I've commented on or you will still have other problems.

@aselle
Copy link
Contributor

aselle commented Jan 4, 2017

Strided_slice has made the "stride" option optional (defaulting to all ones...) ... this is available in master (but not the release you are using). so you can change

tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)

to

tf.strided_slice(record_bytes, [0], [label_bytes], [1]), tf.int32)

@aselle aselle added stat:awaiting response Waiting on input from the contributor type:support labels Jan 4, 2017
@omo
Copy link

omo commented Jan 5, 2017

@aselle I think it's worth making the code work with 0.12.x as well, even though it already works with the TF master.

The code is referred from the TF tutorial. Many readers of that document would not be familiar with TF code base (that's why they read the introductory document after all.) The example code not working out of the box is discouraging to these new users, IMO.

It might make sense to keep it broken if the API change is large and it's hard to keep the compatibility. But it isn't the case of this issue.

Please take a look at #849 when you have time.
It fixes this issue (and some other small hiccups.)

@utsavgarg
Copy link

I made the changes as put in #849, and the trained the model. But during evaluation I get the error:

Traceback (most recent call last):
File "cifar10_eval.py", line 157, in
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "cifar10_eval.py", line 153, in main
evaluate()
File "cifar10_eval.py", line 121, in evaluate
images, labels = cifar10.inputs(eval_data=eval_data)
File "/home/utsav/DeepEmbedding/cifar10/cifar10.py", line 182, in inputs
batch_size=FLAGS.batch_size)
File "/home/utsav/DeepEmbedding/cifar10/cifar10_input.py", line 253, in inputs
shuffle=False)
File "/home/utsav/DeepEmbedding/cifar10/cifar10_input.py", line 132, in _generate_image_and_label_batch
capacity=min_queue_examples + 3 * batch_size)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/input.py", line 683, in batch
capacity=capacity, dtypes=types, shapes=shapes, shared_name=shared_name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 666, in init
shapes = _as_shape_list(shapes, dtypes)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 75, in _as_shape_list
raise ValueError("All shapes must be fully defined: %s" % shapes)
ValueError: All shapes must be fully defined: [TensorShape([Dimension(24), Dimension(24), Dimension(3)]), TensorShape([Dimension(None)])]

@SamuelMarks
Copy link
Contributor

Here's my .patch file: https://gist.github.com/SamuelMarks/17e968288545042da4e718e886e458e3

But it gives me:

$ python cifar10_train.py
>> Downloading cifar-10-binary.tar.gz 100.0%
Successfully downloaded cifar-10-binary.tar.gz 170052171 bytes.
Traceback (most recent call last):
  File "cifar10_train.py", line 120, in <module>
    tf.app.run()
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "cifar10_train.py", line 116, in main
    train()
  File "cifar10_train.py", line 63, in train
    images, labels = cifar10.distorted_inputs()
  File "tensorflow/models/tutorials/image/cifar10/cifar10.py", line 156, in distorted_inputs
    batch_size=FLAGS.batch_size)
  File "tensorflow/models/tutorials/image/cifar10/cifar10_input.py", line 161, in distorted_inputs
    read_input = read_cifar10(filename_queue)
  File "tensorflow/models/tutorials/image/cifar10/cifar10_input.py", line 87, in read_cifar10
    tf.strided_slice(record_bytes, [0], [label_bytes], [1,1]), tf.int32)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 590, in strided_slice
    shrink_axis_mask=shrink_axis_mask)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 3503, in strided_slice
    shrink_axis_mask=shrink_axis_mask, name=name)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
    op_def=op_def)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2242, in create_op
    set_shapes_for_outputs(ret)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1617, in set_shapes_for_outputs
    shapes = shape_func(op)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1568, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn
    debug_python_shape_fn, require_shape_fn)
  File ".venvs/tflow/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 675, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Dimension 0 in both shapes must be equal, but are 1 and 2 for 'StridedSlice' (op: 'StridedSlice') with input shapes: [?], [1], [1], [2].

@omo
Copy link

omo commented Jan 6, 2017

@utsavgarg Thanks for the catch! Just noticed that and fixed #849 accordingly.

@jart jart added type:bug Bug in the code and removed stat:awaiting response Waiting on input from the contributor type:support labels Jan 16, 2017
@jart
Copy link
Contributor

jart commented Jan 16, 2017

Closing because fix from previous comment was submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Bug in the code
Projects
None yet
Development

No branches or pull requests