【问题标题】:How to define a file path when dealing with Tensorflow?处理Tensorflow时如何定义文件路径?
【发布时间】:2019-12-24 22:07:13
【问题描述】:

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

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

错误:(NameError:名称'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')

【问题讨论】:

  • 你有没有研究过这个错误?即使是像一个好的 IDE 这样的东西也会指出这个问题......
  • 我正在使用 google 代码实验室的示例,该示例使用了基于 googleapi 存储的图像路径,这让我很失望。

标签: python tensorflow artificial-intelligence tensorflow-lite


【解决方案1】:

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

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

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

执行代码之前:

data = ImageClassifierDataLoader.from_folder(oranges)

【讨论】:

  • 非常感谢,我没有意识到我们必须事先定义路径。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-25
相关资源
最近更新 更多