我在 ubuntu 20.04 上有一个 python venv,在那里我使用 Tensorflow 来训练我的模型。有一个名为 Persona 的文件夹,它有 5 个子文件夹作为类。每个子文件夹都包含图像文件,一些文件名是阿拉伯语和波斯语。没有问题,一切都很好,直到我将所有这些文件迁移到另一个设备,其操作系统是 windows11。设置好我的环境和所有内容后,当我尝试运行我的代码时,我收到了此错误:
return _pywrap_file_io.IsDirectory(compat.path_to_bytes(path))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcc in position 49: invalid continuation byte
错误发生在我使用 Keras 导入模型数据的以下代码的第二行:
image_path = 'D:\\Desktop\\tfmm\\Personas\\'
train_ds = tf.keras.utils.image_dataset_from_directory(
image_path,
labels="inferred",
label_mode="int",
class_names=None,
color_mode="rgb",
batch_size=32,
image_size=(256, 256),
shuffle=True,
seed=123,
validation_split=0.2,
subset='training',
interpolation="bilinear",
follow_links=False,
crop_to_aspect_ratio=False
)
如有任何帮助,我们将不胜感激。
我在google和github上搜索寻找原因和解决方案,但没有运气。我还在 stackoverflow 上发现了这个问题,没有可接受的答案error-importing-image-dataset-in-tensorflow 我通过将所有图像文件重命名为基于拉丁的编码解决了这个问题,但是当我需要保留原始文件名时,这会很痛苦。
我认为你应该删除路径字符串中的最后一个“\”。