LICENSE.txt 将数据加载到 tensorflow 迁移学习时

LICENSE.txt when loading data into tensorflow transfer learning

我正在使用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 循环时,我真的不知道会发生什么,但它给了我一个关键错误,关键是文件名。

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

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

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))