Reputation: 11
I was trying to link the Javascript Electron app with the python deep learning engine by using PYthon-shell. But I don't know where to go now.
This is the python code:
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()
The javascript code looks like:
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);
})
}
Here is the error output:
index.js:35 Uncaught ReferenceError: Cannot access 'PythonShell' before initialization
at jsFunction
Upvotes: -3
Views: 181
Reputation: 11592
I'm pretty sure
PythonShell = new PythonShell('numbers.py', pyInput);
should read
pyshell = new PythonShell('numbers.py', pyInput);
Also you've misspelt alert
as aler
.
Upvotes: 1