处理Tensorflow时如何定义文件路径?

How to define a file path when dealing with Tensorflow?

这个问题已经解决了,很抱歉浪费了任何时间,由于硬件限制,我使用的是 notepad++,所以我不知道需要导入 OS 来定义文件路径

我正在尝试创建 TFLite 模型,我画了一个箭头指向出现文件路径错误的位置:

错误:(名称错误:名称 'oranges' 未定义)

from __future__ import absolute_import, division, print_function, unicode_literals

import numpy as np

import tensorflow as tf
assert tf.__version__.startswith('2')

from tensorflow_examples.lite.model_customization.core.data_util.image_dataloader import ImageClassifierDataLoader
from tensorflow_examples.lite.model_customization.core.task import image_classifier
from tensorflow_examples.lite.model_customization.core.task.model_spec import efficientnet_b0_spec
from tensorflow_examples.lite.model_customization.core.task.model_spec import ImageModelSpec

import matplotlib.pyplot as plt

data = ImageClassifierDataLoader.from_folder(oranges) <-- oranges is a folder containing the test 
                                                          images. It is in the same folder as this file
model = image_classifier.create(data)

loss, accuracy = model.evaluate()

model.export('image_classifier.tflite', 'image_labels.txt')

path 必须是包含您的建模图像的文件夹。在这种情况下,条目 oranges 未在代码中的任何位置定义为文件夹路径。

要创建文件夹路径,运行:

import os
oranges = os.path.abspath('oranges')

执行代码前:

data = ImageClassifierDataLoader.from_folder(oranges)