【发布时间】:2021-02-23 10:32:03
【问题描述】:
我试图通过使用 PYthon-shell 将 Javascript Electron 应用程序与 python 深度学习引擎链接起来。但我现在不知道该去哪里。
这是python代码:
from keras.models import load_model
import cv2
import numpy as np
import os
from PIL import ImageTk, Image
from sklearn.preprocessing import label
import sys
model = load_model('model.h5')
model.compile(optimizer='adam', loss='binary_crossentropy',
metrics=['accuracy'])
img = cv2.imread('file/4/1.jpg')
img = np.reshape(img, [1, 28, 28, 3])
class1 = model.predict_classes(img)
print("the pridicted number is", class1 + 1)
sys.stdout.flush()
javascript 代码如下所示:
let {PythonShell} = require('python-shell')
var path = require('path');
function getPrediction() {
let pyInput ={
scriptPath : path.join('/../BackEnd/'),
pyPaht :path.join( '/../BackEnd/')
}
PythonShell = new PythonShell('numbers.py', pyInput);
pyshell.on('message', function(message) {
alert(message);
})
}
这是错误输出:
index.js:35 Uncaught ReferenceError: Cannot access 'PythonShell' before initialization
at jsFunction
【问题讨论】:
-
出了什么问题?用错误/输出更新问题,以便人们可以尝试回答。 ;)
-
这里是错误输出 "index.js:35 Uncaught ReferenceError: Cannot access 'PythonShell' before initialization at jsFunction
标签: javascript electron revitpythonshell