mahesh1209 commited on
Commit
963df84
Β·
verified Β·
1 Parent(s): b3ff04d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -4,7 +4,7 @@ from tensorflow.keras.applications import EfficientNetB0, ResNet50
4
  from tensorflow.keras.applications.efficientnet import preprocess_input as efficient_preprocess
5
  from tensorflow.keras.applications.resnet import preprocess_input as resnet_preprocess
6
  from tensorflow.keras.preprocessing import image
7
- from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
8
  from tensorflow.keras.models import Model
9
  import numpy as np
10
 
@@ -13,10 +13,13 @@ IMG_SIZE = 224
13
  MODEL_TYPE = "efficientnet" # or "resnet"
14
  CLASS_NAMES = ['Cat', 'Dog', 'Panda'] # Replace with your actual classes
15
 
 
 
 
16
  # βœ… Load Base Model
17
- base_model = EfficientNetB0(weights='imagenet', include_top=False, input_shape=(IMG_SIZE, IMG_SIZE, 3)) \
18
  if MODEL_TYPE == "efficientnet" else \
19
- ResNet50(weights='imagenet', include_top=False, input_shape=(IMG_SIZE, IMG_SIZE, 3))
20
  base_model.trainable = False
21
 
22
  # βœ… Build Classifier
@@ -28,7 +31,7 @@ model = Model(inputs=base_model.input, outputs=output)
28
  # βœ… Compile & Load Weights (Optional)
29
  model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
30
  try:
31
- model.load_weights("your_weights.h5") # Optional: load pretrained weights
32
  except Exception as e:
33
  print("⚠️ Could not load weights:", e)
34
 
 
4
  from tensorflow.keras.applications.efficientnet import preprocess_input as efficient_preprocess
5
  from tensorflow.keras.applications.resnet import preprocess_input as resnet_preprocess
6
  from tensorflow.keras.preprocessing import image
7
+ from tensorflow.keras.layers import Input, Dense, GlobalAveragePooling2D
8
  from tensorflow.keras.models import Model
9
  import numpy as np
10
 
 
13
  MODEL_TYPE = "efficientnet" # or "resnet"
14
  CLASS_NAMES = ['Cat', 'Dog', 'Panda'] # Replace with your actual classes
15
 
16
+ # βœ… Input Tensor
17
+ input_tensor = Input(shape=(IMG_SIZE, IMG_SIZE, 3))
18
+
19
  # βœ… Load Base Model
20
+ base_model = EfficientNetB0(weights='imagenet', include_top=False, input_tensor=input_tensor) \
21
  if MODEL_TYPE == "efficientnet" else \
22
+ ResNet50(weights='imagenet', include_top=False, input_tensor=input_tensor)
23
  base_model.trainable = False
24
 
25
  # βœ… Build Classifier
 
31
  # βœ… Compile & Load Weights (Optional)
32
  model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
33
  try:
34
+ model.load_weights("your_weights.h5")
35
  except Exception as e:
36
  print("⚠️ Could not load weights:", e)
37