models icon indicating copy to clipboard operation
models copied to clipboard

Tensorflow[attention_ocr] Dimension Error

Open ibr123 opened this issue 9 years ago • 1 comments

Hi,

I intend to make detection using attention_ocr so I'm using the following code

import skimage.io as io
import numpy as np
import collections
import os
import tensorflow as tf
import common_flags
import model
import pdb

from tensorflow.python.platform import flags

FLAGS = flags.FLAGS
common_flags.define()

#pdb.set_trace()
images_placeholder = tf.placeholder(tf.float32, shape=[635, 1219])
fn ='/home/ubuntu/tensorflow/6m.jpg'
images = [io.imread(fn, dtype='float')]
print(images)
images_actual_data = np.stack(images)
images_actual_data = 2.5*(images_actual_data - 0.5)  # normalize values


#model = common_flags.create_model(69,23,1,68) # based on the trained model
dataset = common_flags.create_dataset(split_name=FLAGS.split_name)
modelout = common_flags.create_model(dataset.num_char_classes,
                                    dataset.max_sequence_length,
                                    dataset.num_of_views, dataset.null_code)
#pdb.set_trace()
#endpoints = model.Model.create_base(images_placeholder, labels_one_hot=None)
endpoints = modelout.create_base(images_placeholder, labels_one_hot=None)

with tf.Session() as sess:
    init_fn = model.create_init_fn_to_restore('/nsfs/tensor_models/models/research/attention_ocr/python/inception_v3.ckpt', '')
    init_fn(sess)
    sess.run(tf.global_variables_initializer()) # tried to run sess.run(init_fn) here, but it fails
    predictions = sess.run(endpoints.predicted_chars, feed_dict={images_placeholder:images_actual_data.reshape(1,imHeight,imWidth,imChannel)})
    print predictions`

and I'm getting the following error

Traceback (most recent call last):
  File "run_tf.py", line 32, in <module>
    endpoints = modelout.create_base(images_placeholder, labels_one_hot=None)
  File "/nsfs/tensor_models/models/research/attention_ocr/python/model.py", line 358, in create_base
    value=images, num_or_size_splits=self._params.num_views, axis=2)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1265, in split
    split_dim=axis, num_split=num_or_size_splits, value=value, name=name)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 5094, in _split
    name=name)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2958, in create_op
    set_shapes_for_outputs(ret)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn
    require_shape_fn)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Dimension size, given by scalar input 2 must be in range [-2, 2) for 'AttentionOcr_v1/split' (op: 'Split') with input shapes: [], [635,1219] and with computed input tensors: input[0] = <2>.

any idea to solve this problem? Thanks

ibr123 avatar Nov 21 '17 15:11 ibr123

This question is better asked on StackOverflow since it is not a bug or feature request. There is also a larger community that reads questions there. Thanks!

aselle avatar Nov 29 '17 21:11 aselle