首页 > 解决方案 > 将数据加载到 tensorflow 迁移学习时的 LICENSE.txt

问题描述

我正在使用 tensorflow 提供的代码来加载数据:https ://www.tensorflow.org/beta/tutorials/load_data/text

当我放入自己的照片时,它会发送到不同的目录。该代码需要来自我的 LICENSE.txt 的属性,但我不确定此代码段的用途是什么。

我制作了我自己的 LICENSE.txt 文件,只制作了一个文本文件,每一行都是图像的标题。当我这样做时,它使属性成为一个字典,其中每个键是文件名,每个对应的值是''。当我运行另一种方法时,每个文件都会出现一个关键错误。

import os
attributions = (data_root/"LICENSE.txt").open(encoding='utf- 8').readlines()
attributions = [line.split('\n') for line in attributions]
print(attributions)
attributions = dict(attributions)

import IPython.display as display

def caption_image(image_path):
    image_rel = pathlib.Path(image_path).relative_to(data_root)
    return "Image (CC BY 2.0) " + ' -'.join(attributions[str(image_rel)].split(' - ')[:-1])

for n in range(3):
  image_path = random.choice(all_image_paths)
  display.display(display.Image(image_path))
  print(caption_image(image_path))
  print()

当我在 jupyter notebook 中运行 for 循环时,我真的不知道会发生什么,但它给了我一个关键错误,关键是文件名。

标签: tensorflowkerasfilepath

解决方案


我写了那个教程。许可证查找仅存在于此处,因此我们可以在发布时直接对各个摄影师进行艺术归属。如果您使用自己的图像,则根本不需要这部分代码。

它真正做的只是选择一个随机图像并显示它。您可以将其简化为:

import os

import IPython.display as display

for n in range(3):
  image_path = random.choice(all_image_paths)
  display.display(display.Image(image_path))

推荐阅读