【发布时间】:2020-10-07 00:37:46
【问题描述】:
我正在尝试安装 cv2 和 nmpy 等模块,找到了一些解决方案,但使用它们时,每次使用 shell 时都会进行安装,这会增加响应时间。
这是我用来调用python函数的nodeJS中的函数
`app.post("/img", (req, res) => {
callNumber(req,res);
});
function callNumber(req,res){
var spawn= require('child_process').spawn;
var process = spawn('python',
['./saved_model_exec.py',req.body.imgURL]);
process.stdout.on('data',function(data){
res.send(data.toString());
})
}`
这是我要运行的 python 文件
`import tensorflow as tf
import cv2
import numpy as np
import sys
model = tf.keras.models.load_model('mnist.h5')
img = cv2.imread('test.png', 0)
img_resized = img.resize(28, 28)
img_resized = np.array(img)
img_reshaped = img_resized.reshape(1, 28, 28, 1)
img_reshaped = img_reshaped/255.0
res = model.predict([img_reshaped])[0]
digit, accuracy = np.argmax(res), max(res)
print(str(digit))`
【问题讨论】:
标签: javascript python node.js express web-development-server