【发布时间】:2019-07-14 14:42:28
【问题描述】:
我正在尝试从这里https://github.com/pytorch/examples/tree/master/fast_neural_style 运行代码,我从终端python neural_style/neural_style.py eval --content-image ./images/content-images/amber.jpg --model ./saved_models/mosaic.pth --output-image a.jpg --cuda 0 运行以下命令,其中a.jpg 是输出图像,但每次我得到一个错误:
Traceback (most recent call last):
File "neural_style/neural_style.py", line 240, in <module>
main()
File "neural_style/neural_style.py", line 236, in main
stylize(args)
File "neural_style/neural_style.py", line 150, in stylize
utils.save_image(args.output_image, output[0])
File "C:\Users\Lenovo\Documents\fast_neural_style\neural_style\utils.py", line 19, in save_image
img.save(filename)
File "C:\Users\Lenovo\Anaconda3\lib\site-packages\PIL\Image.py", line 1991, in save
fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: 'a.jpg'
我尝试在a.jpg 之前使用斜杠和反斜杠的完整路径,但每次仍然出现此错误。
我从终端使用命令python test.py 启动了以下脚本:
from PIL import Image, ImageDraw
text = "test image"
color = (0, 0, 120)
img = Image.new('RGB', (100, 50), color)
imgDrawer = ImageDraw.Draw(img)
imgDrawer.text((10, 20), text)
img.save("pil-example.png")
又出现了一个错误
Traceback (most recent call last):
File "test.py", line 7, in <module>
img.save("pil-example.png")
File "C:\Users\Lenovo\Anaconda3\lib\site-packages\PIL\Image.py", line 1966, in save
fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: 'pil-example.png'
但是当我在jupiter-notebook 中启动这个脚本时,它可以正常工作。
我使用:Windows 10、Python 3.7.1、Pillow 5.3.0。
如果您有任何解决此问题的建议,我将不胜感激!
【问题讨论】:
-
你能尝试给一个固定的路径吗?喜欢:
C:\Users\Fabian\Desktop\image.png -
当我将您的代码复制粘贴到我的 Windows 10 中时,它按预期工作。枕头 5.4.1 和 Python 3.5.0。你也可以试试
with open(filepath, 'w') as f:img.save(f)
标签: python image-processing python-imaging-library pytorch