tensorflow - 将数据加载到 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 循环时,我真的不知道会发生什么,但它给了我一个关键错误,关键是文件名。
解决方案
我写了那个教程。许可证查找仅存在于此处,因此我们可以在发布时直接对各个摄影师进行艺术归属。如果您使用自己的图像,则根本不需要这部分代码。
它真正做的只是选择一个随机图像并显示它。您可以将其简化为:
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))
推荐阅读
- java - Java hangman 用用户输入替换下划线
- linux - arduino IDE 找不到库
- ag-grid - ag-grid 包之间的区别
- angular - AngularFire - 如何将firestore文档映射到valueChanges上的数组?
- javascript - javascript,从大对象数组中返回小对象数组
- express - 如何从 App Engine 服务器获取错误消息?
- node.js - AWS:CloudFormation 中的 Node.js Lambda 函数,用于将文件上传到 DeviceFarm URL
- laravel - 使用原始 SQL 查询插入以避免 SQL 注入?
- r - 检查差异是否小于机器精度的正确/标准方法是什么?
- c - 存储和打印结构数组无法按预期工作