Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <canvas id="myCanvas" width="280" height="280" style="border:8px solid; float: left; margin: 70px; margin-top:160px; border-radius: 5px; cursor: crosshair;"></canvas>
- <script type="text/javascript">
- var mousePressed = false;
- var lastX, lastY;
- var ctx;
- function InitThis() {
- ctx = document.getElementById('myCanvas').getContext("2d");
- $('#myCanvas').mousedown(function (e) {
- mousePressed = true;
- Draw(e.pageX - $(this).offset().left, e.pageY - $(this).offset().top, false);
- });
- $('#myCanvas').mousemove(function (e) {
- if (mousePressed) {
- Draw(e.pageX - $(this).offset().left, e.pageY - $(this).offset().top, true);
- }
- });
- $('#myCanvas').mouseup(function (e) {
- mousePressed = false;
- });
- $('#myCanvas').mouseleave(function (e) {
- mousePressed = false;
- });
- }
- function Draw(x, y, isDown) {
- if (isDown) {
- ctx.beginPath();
- ctx.strokeStyle = 'black';
- ctx.lineWidth = 5;
- ctx.lineJoin = "round";
- ctx.moveTo(lastX, lastY);
- ctx.lineTo(x, y);
- ctx.closePath();
- ctx.stroke();
- }
- lastX = x;
- lastY = y;
- }
- function clearArea() {
- // Use the identity matrix while clearing the canvas
- ctx.setTransform(1, 0, 0, 1, 0, 0);
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
- }
- </script>
- def convertImage(imgData1):
- imgstr = re.search(b'base64,(.*)',imgData1).group(1)
- with open('output.png','wb') as output:
- output.write(base64.b64decode(imgstr))
- def predict():
- imgData = request.get_data()
- convertImage(imgData)
- imgArr = cv2.imread("output.png", 0)
- imgArr = cv2.resize(imgArr, dsize=(28, 28), interpolation=cv2.INTER_CUBIC)
- #print(imgArr)
- imgArr = np.expand_dims(imgArr, axis=0)
- new_model = tf.keras.models.load_model('my-model.model')
- prediction = new_model.predict(imgArr)
- return np.array_str(prediction[0])
- Predicted Output: [0.01503093 0.09207787 0.08750388 0.0216067 0.02371381 0.5564784 0.01984628 0.16058393 0.00308483 0.02007343]
- expecting an output like [0 0 0 1 0 0 0 0 0 0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement