我使用AWSEC2运行我的应用程序“艺术中的神经网络”。为了发送图像,我部署了一个基于flask+virtualenv+apache的网站。在服务器上发送图像后,启动脚本,该脚本打印每个迭代,我要将其存储在其中输出.txt在
__init__.py:
#...
def apply_style(image_name, style_name, iterations):
command = ['"python ~/neural_artistic_style/neural_artistic_style.py', \
' --subject ', '/var/www/superapp/superapp/uploads/' + image_name, \
' --style ', '/var/www/superapp/superapp/uploads/' + style_name, \
' --iterations ', iterations, \
' --network ~/neural_artistic_style/imagenet-vgg-verydeep-19.mat"']
str = ''.join(command)
network = Popen(str, shell=True, stdout=PIPE)
stats = []
for out in network.stdout:
stats.append(out)
line = ' '.join(stats)
return line
@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
image = request.files['image']
style = request.files['style']
iterations = request.form['iter']
if file and style:
#Saving images...
result = apply_style(image_name, style_name, iterations)
f = open('out.txt', 'w')
f.write(result)
f.close()
return 'FINISHED'
#...
好吧,我可以通过HTTP上传图片,而不必写结果顺序文件,但当我这样做时,apache日志显示:
^{pr2}$此目录中的所有文件现在都有777权限。当我试图用简单的脚本写东西时,比如script.py:
f = open('out.txt', 'w')
f.write('some words')
f.close()
一切正常。但对于apache就没有了。有人知道如何修复它吗?在
问题是apache运行您的代码时,它将有一个不同的工作目录,您不打算在其中写入文件。必须提供文件的完整路径。在
相关问题 更多 >
编程相关推荐