我试图运行来自这里的代码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'
但是当我在Jupyter Notebook中运行这个脚本时,它没有出现错误。
我使用的是:Windows 10操作系统,Python 3.7.1版本,Pillow 5.3.0库。
如果您能给我解决这个问题的任何建议,我将非常感激!
C:\Users\Fabian\Desktop\image.png
- Fabianwith open(filepath, 'w') as f: img.save(f)
- Reedinationer