[英]How can I install python packages permanently when I am running my code as a python shell in nodeJS?
我正在嘗試安裝 cv2 和 nmpy 等模塊,找到了一些解決方案,但使用它們時,每次使用 shell 時都會進行安裝,這會增加響應時間。
這是我用來調用 python function 的 nodeJS 中的 function
`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))`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.