title: Why CNN running in python is extremely slow in comparison to Matlab?
body: <p>I have trained a CNN in Matlab 2019b that classifies images between three classes. When this CNN was tested in Matlab it was functioning fine and only took 10-15 seconds to classify an image. I used the exportONNXNetwork function in Maltab so that I can implement my CNN in Tensorflow. This is the code I am using to use the ONNX file in python:</p>
  <pre class="lang-py prettyprint-override"><code>import onnx
  from onnx_tf.backend import prepare 
  import numpy as np
  from PIL import Image 
  
  onnx_model = onnx.load('trainednet.onnx')
  tf_rep = prepare(onnx_model)
  filepath = 'filepath.png' 
  
  img = Image.open(filepath).resize((224,224)).convert(&quot;RGB&quot;) 
  img = array(img).transpose((2,0,1))
  img = np.expand_dims(img, 0) 
  img = img.astype(np.uint8) 
  
  probabilities = tf_rep.run(img) 
  print(probabilities) 
  
  </code></pre>
  <p>When trying to use this code to classify the same test set, it seems to be classifying the images correctly but it is very slow and freezes my computer as it reaches high memory usages of up to 95+% at some points.</p>
  <p>I also noticed in the command prompt while classifying it prints this:</p>
  <pre><code>2020-04-18 18:26:39.214286: W tensorflow/core/grappler/optimizers/meta_optimizer.cc:530] constant_folding failed: Deadline exceeded: constant_folding exceeded deadline., time = 486776.938ms.
  </code></pre>
  <p>Is there any way I can make this python code classify faster?</p>