메뉴 건너뛰기

app

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

lispro062017.07.17 00:12조회 수 4592댓글 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 (비회원)
    • 글자 크기
[FCM] bigtext와 알림 팝업 사용 (by lispro06) [tensorflow] 설치 및 실행 (by lispro06)

댓글 달기

suritam9
2021.12.15 조회 578
suritam9
2020.03.31 조회 1315
suritam9
2019.04.05 조회 2398
suritam9
2019.03.07 조회 528
suritam9
2019.03.06 조회 987
lispro06
2018.03.21 조회 1065
lispro06
2018.03.16 조회 2201
lispro06
2017.11.27 조회 6742
lispro06
2017.07.16 조회 1916
lispro06
2017.06.22 조회 2217
lispro06
2016.11.02 조회 1902
lispro06
2016.11.01 조회 7711
lispro06
2016.10.27 조회 4449
lispro06
2016.10.27 조회 3215
lispro06
2016.10.27 조회 4237
lispro06
2016.10.27 조회 2887
lispro06
2015.11.20 조회 1829
첨부 (0)
위로