Я делаю файл .png для tfrecord.
def _bytes_feature(value):
"""Wrapper for inserting bytes features into Example proto."""
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
преобразовать в файл примера:
def _convert_to_example(filename, image_buffer, label, text, height, width):
example = tf.train.Example(features=tf.train.Features(feature={
'image/height': _int64_feature(height),
'image/width': _int64_feature(width),
........
'image/encoded': _bytes_feature(image_buffer)})) #Error
return example
файл decode_png, не уверен, что эта часть
def decode_png(image_data):
img_str = image_data.tostring()
reconstructed_img_1d = np.fromstring(img_str, dtype=np.uint8)
reconstructed_img = reconstructed_img_1d.reshape(image_data.shape)
return reconstructed_img
файл process_image:
def _process_image(filename):
# Read the image file.
with open(filename, 'r') as f:
image_data = io.imread(f)
# Decode the RGB PNG.
image = decode_png(image_data)
# Check that image converted to RGB
assert len(image.shape) == 3
height = image.shape[0]
width = image.shape[1]
assert image.shape[2] == 3
return image_data, height, width
Основной, пакет файлов образов процесса:
for i in files_in_shard:
filename = filenames[i]
label = labels[i]
text = texts[i]
image_buffer, height, width = _process_image(filename)
example = _convert_to_example(filename, image_buffer, label,
text, height, width)
writer.write(example.SerializeToString())
shard_counter += 1
counter += 1
Но есть ошибка, TypeError: array([[[223, 198, 219],
[215, 185, 209],
[207, 174, 201],
...,
[230 has type numpy.ndarray, but expected one of: bytes
Как мне с этим бороться?Любая помощь будет отличной.Спасибо