python - Why won't tf.write_file write a file?
问题描述
My code is:
i = 0
fgsm = FastGradientMethod(wrap)
adv = fgsm.generate(x_test_tensor, **fgsm_params)
for adv_x in tf.unstack(adv):
img = tf.cast(adv_x, dtype=tf.uint8)
tf_image = tf.image.encode_jpeg(img)
tf.write_file('adversarial_examples/' + str(i) + '.jpg', tf_image)
i += 1
Where FastGradientMethod is from cleverhans
. This runs without an error, but the jpg's don't exist in my folder. What's missing?
解决方案
可能目标文件的路径不正确
import os
for adv_x in tf.unstack(adv):
img = tf.cast(adv_x, dtype=tf.uint8)
tf_image = tf.image.encode_jpeg(img)
pth = os.path.join('adversarial_examples', '%s.jpg'%i)
tf.write_file(pth, tf_image)
i += 1
推荐阅读
- c# - C# 进程文件访问被拒绝
- python - 这是什么“数据转换警告”以及如何解决?
- spring-boot - 用springboot resttemplate下载一个文件
- javascript - 雪花中的 ARRAY_REMOVE()?
- javascript - 使用正则表达式作为撇号
- html - 使下拉菜单的内容居中
- gitlab - 如何在 gitlab 中为我的所有项目使用依赖项存储库?
- uitableview - 如何使用 UIConfigurationColorTransformer 更改 UITableViewCell 背景颜色?
- node.js - 快递端点接收空正文
- node.js - 在 WSL2 上安装 nvm 时,我可以在 Windows 本身中使用它吗?