DSCmatter commited on
Commit
476066c
·
1 Parent(s): 0b4ae93

from .h5 to keras

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.keras filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -1,14 +1,20 @@
1
  import streamlit as st
2
- from tf_keras.models import load_model # <-- switch to tf_keras
 
3
  from tensorflow.keras.preprocessing import image
4
  from tensorflow.keras.applications.resnet50 import preprocess_input
5
  import numpy as np
6
  from PIL import Image
7
 
 
 
8
  @st.cache_resource
9
  def load_my_model():
10
- return load_model("resnet50_dryfruits.h5", compile=False)
 
 
11
 
 
12
  class_names = {
13
  0: 'AlmondGrade_A',
14
  1: 'CashewGrade_B',
@@ -20,25 +26,31 @@ class_names = {
20
  7: 'WalnutGrade_A',
21
  8: 'CashewGrade_C'
22
  }
 
23
 
24
  model = load_my_model()
25
 
 
26
  st.title("Dry Fruit Quality Grader")
27
  st.write("Upload an image of a dry fruit, and the model will predict its grade.")
28
 
29
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
30
 
31
  if uploaded_file is not None:
32
- img = Image.open(uploaded_file).convert("RGB")
 
33
  img = img.resize((224, 224))
34
  img_array = image.img_to_array(img)
35
  img_batch = np.expand_dims(img_array, axis=0)
36
  img_preprocessed = preprocess_input(img_batch)
37
-
38
- preds = model.predict(img_preprocessed)
39
- idx = int(np.argmax(preds[0]))
40
- confidence = float(np.max(preds[0]))
41
-
 
 
 
42
  st.image(img, caption="Uploaded Image", use_column_width=True)
43
- st.markdown(f"## Prediction: **{class_names[idx]}**")
44
  st.markdown(f"### Confidence: **{confidence * 100:.2f}%**")
 
1
  import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.models import load_model
4
  from tensorflow.keras.preprocessing import image
5
  from tensorflow.keras.applications.resnet50 import preprocess_input
6
  import numpy as np
7
  from PIL import Image
8
 
9
+ # --- Load Your Model and Class Names ---
10
+ # Use st.cache_resource to load the model only once
11
  @st.cache_resource
12
  def load_my_model():
13
+ # Make sure this file name matches your model file
14
+ model = load_model('resnet50_dryfruits.keras')
15
+ return model
16
 
17
+ # --- This is the updated dictionary based on your list ---
18
  class_names = {
19
  0: 'AlmondGrade_A',
20
  1: 'CashewGrade_B',
 
26
  7: 'WalnutGrade_A',
27
  8: 'CashewGrade_C'
28
  }
29
+ # --------------------------------------------------------
30
 
31
  model = load_my_model()
32
 
33
+ # --- App Interface ---
34
  st.title("Dry Fruit Quality Grader")
35
  st.write("Upload an image of a dry fruit, and the model will predict its grade.")
36
 
37
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
38
 
39
  if uploaded_file is not None:
40
+ # 1. Preprocess the image
41
+ img = Image.open(uploaded_file).convert('RGB') # Ensure 3 channels
42
  img = img.resize((224, 224))
43
  img_array = image.img_to_array(img)
44
  img_batch = np.expand_dims(img_array, axis=0)
45
  img_preprocessed = preprocess_input(img_batch)
46
+
47
+ # 2. Make prediction
48
+ prediction = model.predict(img_preprocessed)
49
+ predicted_index = np.argmax(prediction[0])
50
+ predicted_class_name = class_names[predicted_index]
51
+ confidence = np.max(prediction[0])
52
+
53
+ # 3. Display results
54
  st.image(img, caption="Uploaded Image", use_column_width=True)
55
+ st.markdown(f"## Prediction: **{predicted_class_name}**")
56
  st.markdown(f"### Confidence: **{confidence * 100:.2f}%**")
resnet50_dryfruits.h5 → resnet50_dryfruits.keras RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a4d1c65a486780cb6e1c33c9bda9eae34edb0c658ea450ca8cab12f064787d0e
3
- size 286585880
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb526f58f4a6b027e5bb9cab55b7a51040b9e4dffdad8c64a0f71ba7f7234cef
3
+ size 96054159