sthalles/face-similarity

Failed with my own tfrecords.

Closed this issue · 2 comments

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?

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]

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

It runs ok now. Thank you.