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

dataset patch error #1

Open
superhg2012 opened this issue Jul 30, 2018 · 4 comments
Open

dataset patch error #1

superhg2012 opened this issue Jul 30, 2018 · 4 comments

Comments

@superhg2012
Copy link

Hi, an error thrown when run train, could you help to see this problem?

Traceback (most recent call last):
File "main.py", line 414, in
tf.app.run(main=train_or_predict)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "main.py", line 405, in train_or_predict
hparams=params,
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/learn_runner.py", line 218, in run
return _execute_schedule(experiment, schedule)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/learn_runner.py", line 46, in _execute_schedule
return task()
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/experiment.py", line 625, in train_and_evaluate
self.train(delay_secs=0)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/experiment.py", line 367, in train
hooks=self._train_monitors + extra_hooks)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/experiment.py", line 807, in _call_train
hooks=hooks)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 302, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 708, in _train_model
input_fn, model_fn_lib.ModeKeys.TRAIN)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 577, in _get_features_and_labels_from_input_fn
result = self._call_input_fn(input_fn, mode)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 663, in _call_input_fn
return input_fn(**kwargs)
File "main.py", line 218, in input_fn
padded_shapes=([None, None, None],[])
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 695, in padded_batch
return PaddedBatchDataset(self, batch_size, padded_shapes, padding_values)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1292, in init
input_dataset.output_shapes, _partial_shape_to_tensor, padded_shapes)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/util/nest.py", line 512, in map_structure_up_to
assert_shallow_structure(shallow_tree, input_tree)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/util/nest.py", line 372, in assert_shallow_structure
check_types=check_types)
File "/data0/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/util/nest.py", line 356, in assert_shallow_structure
"Input has type: %s." % type(input_tree))
TypeError: If shallow structure is a sequence, input must also be a sequence. Input has type: <class 'list'>.

@superhg2012
Copy link
Author

@naktinis can you help to see this issue? thanks in advance!

@naktinis
Copy link
Contributor

@superhg2012 the respository is not actively maintained. If you paste here the exact commands you executed when you got this error, I may try to replicate it when I have time.

@superhg2012
Copy link
Author

@naktinis
I use the voxforge corpus only. and I use the code from the main branch.
I run this train command:

python main.py --model-dir /data0/cnn_models --model cnn --image-dir /data0/vox_pngs/ --train-set /data0/vox_pngs/train-set.csv --eval-set /data0/vox_pngs/eval-set.csv

the problem seems caused by this tuple ( {'sgam' : features}, labels): there are two code snaps in the project.

1 dataset.py

@staticmethod
  def instance_as_tensor(image_name, label=None):
      """Convert a single training/prediction instance into a tensor."""
      print(image_name)
      img_file = tf.read_file(image_name)
      image = tf.image.decode_png(img_file, channels=0)
      image = tf.cast(image, tf.float32)
      image_data = tf.transpose(image[:128, :] / 256.)

      if label is not None:
          label = tf.cast(label, tf.int32)

      return {'sgram': image_data}, label

2 main.py

    def input_fn():
        dataset = tf.data.Dataset.from_tensor_slices(usable_data)
        dataset = dataset.shuffle(params.shuffle_buffer_size)
        dataset = dataset.map(data.instance_as_tensor)
        dataset = dataset.repeat(epochs)
        dataset = dataset.padded_batch(params.batch_size, padded_shapes=([None, None, None], []), padding_values=0.0)

        iterator = dataset.make_initializable_iterator()
        init_hook.iterator_init = iterator.initializer
        next_example, next_label = iterator.get_next()
        return {'sgram': next_example}, next_label

when I modify {'sgram': next_example}, next_label to next_example, next_label and

{'sgram': image_data}, label to image_data, label

the train process can run without problem.

I do not know why.

Another question:

the spectrogram_width is set to 858, pngs are generated from audios which is ? X 128 in size. ? is different for audios with different duration. So some pngs is less than 858 in width, so when train cnn model, these pngs will fail since cnn require fixed filter size. I see that the tensorflow dataset Api is used to padding batch to same size, Is this is used to process the pngs whose spectrogram_width is less than 858? if not, how can I deal with those small pngs?
dataset = dataset.padded_batch(params.batch_size, padded_shapes=([None, None, None], []))

@superhg2012
Copy link
Author

@naktinis

When run with predict, another exception throws:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Index out of range using input dim 3; input has only 3 dims for 'strided_slice_2' (op: 'StridedSlice') with input shapes: [?,?,?], [4], [4], [4] and with computed input tensors: input[3] = <1 1 1 1>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants