chandan06 commited on
Commit
fdde1dc
·
1 Parent(s): 63bd0b3

Update classification.py

Browse files
Files changed (1) hide show
  1. classification.py +11 -10
classification.py CHANGED
@@ -4,9 +4,9 @@ from tensorflow.keras.preprocessing import image
4
  # from tensorflow.keras.preprocessing.image import ImageDataGenerator
5
  import tensorflow as tf
6
  import streamlit as st
7
- # with tf.device('/cpu:0'):
8
  # Load the saved model
9
- model = tf.keras.models.load_model('best_resnet152_model.h5')
10
 
11
  class_names = {0: '1099_Div', 1: '1099_Int', 2: 'Non_Form', 3: 'w_2', 4: 'w_3'}
12
  # print(class_names)
@@ -21,14 +21,15 @@ def predict(pil_img):
21
  img_array /= 255.0 # Rescale pixel values
22
 
23
  # Predict the class
24
- start_time = time.time()
25
- predictions = model.predict(img_array)
26
- end_time = time.time()
27
- predicted_class_index = np.argmax(predictions, axis=1)[0]
28
-
29
- # Get the predicted class name
30
- predicted_class_name = class_names[predicted_class_index]
31
- print("Predicted class:", predicted_class_name)
 
32
  # print("Execution time: ", end_time - start_time)
33
  return predicted_class_name
34
  # import numpy as np
 
4
  # from tensorflow.keras.preprocessing.image import ImageDataGenerator
5
  import tensorflow as tf
6
  import streamlit as st
7
+ with tf.device('/cpu:0'):
8
  # Load the saved model
9
+ model = tf.keras.models.load_model('best_resnet152_model.h5')
10
 
11
  class_names = {0: '1099_Div', 1: '1099_Int', 2: 'Non_Form', 3: 'w_2', 4: 'w_3'}
12
  # print(class_names)
 
21
  img_array /= 255.0 # Rescale pixel values
22
 
23
  # Predict the class
24
+ with tf.device('/cpu:0'):
25
+ start_time = time.time()
26
+ predictions = model.predict(img_array)
27
+ end_time = time.time()
28
+ predicted_class_index = np.argmax(predictions, axis=1)[0]
29
+
30
+ # Get the predicted class name
31
+ predicted_class_name = class_names[predicted_class_index]
32
+ print("Predicted class:", predicted_class_name)
33
  # print("Execution time: ", end_time - start_time)
34
  return predicted_class_name
35
  # import numpy as np