我正在尝试加载我生成的自定义png文件来训练我的模型。遵循TensorFlow指南这里的说明,我使用了以下代码:
import tensorflow as tf
import numpy as np
from pathlib import Path, WindowPath
train_df = pd.DataFrame(
{'file_name': {0: WindowsPath('hypothesis/temp/81882f4e-0a94-4446-b4ac-7869cf198534.png'), 1: WindowsPath('hypothesis/temp/531162e2-2b4c-4e64-8b3f-1f285b0e1040.png')}, 'label': {0: -0.019687398020669655, 1: 0.0002379227226001479}}
)
file_path_list = [i.read_bytes() for i in train_df['file_name']]
dataset = tf.data.TFRecordDataset(filenames=file_path_list)
raw_example = next(iter(dataset))
parsed = tf.train.Example.FromString(raw_example.numpy())
运行 raw_example...
这一行会返回以下错误信息:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 43: invalid start byte
我使用matplotlib生成了PNG文件。
tf.train.Example.FromString
来加载它会导致以下错误:tensorflow.python.framework.errors_impl.DataLossError: corrupted record at 0
。 - Mehdi Zare