메뉴 건너뛰기

app

[flask] 외부 인자 받기 및 python 파일 실행

lispro062017.07.17 00:12조회 수 4167댓글 0

    • 글자 크기

flask 는 기본적으로 tensorflow에 포함되어 있는 듯 하다.


아래 코드로 4_softmax.py 를 실행시킬 때, 외부 인자를 받아서 prediction 할 값을 배열로 처리할 수 있다.


from flask import Flask

import subprocess

from flask import request

app = Flask(__name__)


@app.route('/')

def hello_world():

    arg = "4_softmax.py " + request.args.get('arg')

    

    p = subprocess.Popen(arg , stdout=subprocess.PIPE, shell=True)

 

## Talk with date command i.e. read data from stdout and stderr. Store this info in tuple ##

    (output, err) = p.communicate()

    

## Wait for date to terminate. Get return returncode ##

    #p_status = p.wait()

    #print ("Command output : ", output)

    #print ("Command exit status/return code : ", p_status)

    return output

if __name__ == '__main__':

app.run(host='0.0.0.0',port=8000)



8000번 포트로 ~/?arg=1 8 2


로 호출하면, get parameter를 배열로 넣어 예측이 필요한 값을 지정할 수 있다.

sys를 임포트 해주고, X 에 들어가는 인자에서 파일명에 해당하는 첫번째 인자를 제거 후 2중 배열로 처리한다.


출력은 prediction 값은 제하고 arg_max에 의한 값만 return 하도록 했다.


import sys


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    del sys.argv[0]

    

    prediction = sess.run(hypothesis, feed_dict={X: [sys.argv]})

    print (sess.run(tf.arg_max(prediction, 1)[0]))


lispro06 (비회원)
    • 글자 크기

댓글 달기

박영식
2006.09.01 조회 1412
lispro06
2015.05.15 조회 1453
lispro06
2015.05.15 조회 1467
lispro06
2015.11.20 조회 1471
lispro06
2013.12.11 조회 1484
suritam9
2013.11.26 조회 1490
lispro06
2016.11.02 조회 1566
lispro06
2014.08.16 조회 1568
lispro06
2017.07.16 조회 1593
이전 1 2 3 4 5 6 7 8 9 10... 14다음
첨부 (0)
위로