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

Failed with my own tfrecords. #2

Closed
dyyzhmm opened this issue Jun 17, 2019 · 2 comments
Closed

Failed with my own tfrecords. #2

dyyzhmm opened this issue Jun 17, 2019 · 2 comments

Comments

@dyyzhmm
Copy link

dyyzhmm commented Jun 17, 2019

Thank you for your share.
I got a problem when I run it with my own data.
I make bmp files to tfrecords with code below:

import tensorflow as tf
import cv2
import numpy as np

datalistfile = './images/data'
''' format of datalistfile
0 ./images/cgh_0.bmp ./images/cgh_10.bmp
0 ./images/cgh_10.bmp ./images/cgh_11.bmp
'''
dataf = open(datalistfile,'r')
writer = tf.python_io.TFRecordWriter("test.tfrecords")

def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value = [value]))

def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value = [value]))

data = dataf.readlines()
for i in range(len(data)):
line = data[i]
line = line.strip()
line = line.split(" ")
Xi = tf.gfile.FastGFile(line[1], 'rb').read() # image data type is string
Xj = tf.gfile.FastGFile(line[2], 'rb').read() # image data type is string
image_shape = cv2.imread(line[1]).shape
width = image_shape[1]
height = image_shape[0]
label = int(line[0])
features = {
'Xi': _bytes_feature(Xi),
'Xj': _bytes_feature(Xj),
"label": _int64_feature(label),
"height": _int64_feature(height),
"width": _int64_feature(width)
}
example = tf.train.Example(features = tf.train.Features(feature=features))
writer.write(example.SerializeToString())
writer.close()

So , can you tell me how do you make your test_v2.tfrecords from images?

@dyyzhmm
Copy link
Author

dyyzhmm commented Jun 17, 2019

The trace log is:
InvalidArgumentError Traceback (most recent call last)
in ()
4
5 print (type(test_dataset))
----> 6 for (batch,(Xi, Xj,label )) in enumerate(test_dataset):
7 print (Xi.shape)
8

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/iterator_ops.py in next(self)
522
523 def next(self): # For Python 3 compatibility
--> 524 return self.next()
525
526 def _next_internal(self):

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/iterator_ops.py in next(self)
553 """
554 try:
--> 555 return self._next_internal()
556 except errors.OutOfRangeError:
557 raise StopIteration

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/iterator_ops.py in _next_internal(self)
543 self._resource,
544 output_types=self._flat_output_types,
--> 545 output_shapes=self._flat_output_shapes)
546
547 return sparse.deserialize_sparse_tensors(

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_dataset_ops.py in iterator_get_next_sync(iterator, output_types, output_shapes, name)
2181 else:
2182 message = e.message
-> 2183 _six.raise_from(_core._status_to_exception(e.code, message), None)
2184
2185

~/anaconda3/lib/python3.6/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: Input to reshape is a tensor with 37686 values, but the requested shape has 37632
[[Node: image_reshape = Reshape[T=DT_UINT8, Tshape=DT_INT32](DecodeRaw, image_reshape/shape)]] [Op:IteratorGetNextSync]

@dyyzhmm
Copy link
Author

dyyzhmm commented Jun 18, 2019

I fixed it by comment out one line code:
#test_dataset = test_dataset.map(random_resize_and_crop)

It runs ok now. Thank you.

@dyyzhmm dyyzhmm closed this as completed Jun 18, 2019
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

1 participant