title: conversion of dimension of streamlit canvas image
body: <p>I am building a digit-recognizer neural network model on python. when I am feeding the testing image through a stream-lit canvas into the model I have to convert the 3D image into 2D and then to (1,28,28). but after that my model cannot predict the image even if it has a 97% accuracy. Can somebody help me. this is my code:-</p>
  <pre><code>%%writefile app.py
  import pandas as pd
  from PIL import Image
  import streamlit as st
  from streamlit_drawable_canvas import st_canvas
  import numpy as np
  import tensorflow as tf
  import matplotlib.pyplot as plt
  from tensorflow import keras
  # Specify canvas parameters in application
  stroke_width = st.sidebar.slider(&quot;Stroke width: &quot;, 1, 25, 3)
  stroke_color = '#ffffff'
  bg_color = '#000000'
  drawing_mode = st.sidebar.selectbox(
      &quot;Drawing tool:&quot;, (&quot;freedraw&quot;, &quot;line&quot;, &quot;rect&quot;, &quot;circle&quot;, &quot;transform&quot;)
  )
  realtime_update = st.sidebar.checkbox(&quot;Update in realtime&quot;, True)
  model_new=keras.models.load_model('digitrecognizer_mnist.hdf5')
  
  # Create a canvas component
  canvas_result = st_canvas(
      fill_color=&quot;#000000&quot;,  # Fixed fill color with some opacity
      stroke_width=stroke_width,
      stroke_color=stroke_color,
      background_color=bg_color,
      update_streamlit=realtime_update,
      height=150,width=150,
      drawing_mode=drawing_mode,
      key=&quot;canvas&quot;,
  )
  import cv2 
  import matplotlib.pyplot as plt
  from google.colab.patches import cv2_imshow
  a=np.ones([150,150],dtype='uint8')*255
  st.write(canvas_result.image_data.shape)
  img=np.asarray(canvas_result.image_data).astype(np.uint8)
  img.resize((28,28))
  st.write(img.shape)
  img=img.reshape(1,28,28)
  k=model_new.predict_classes(img)[0]
  if st.button('PREDICT'):
    st.write('Predicted value is') 
    st.write(k)
  </code></pre>