Basak Tamer commited on
Commit
735bfeb
·
verified ·
1 Parent(s): cd6e967

Delete src/cifar10_app.py

Browse files
Files changed (1) hide show
  1. src/cifar10_app.py +0 -73
src/cifar10_app.py DELETED
@@ -1,73 +0,0 @@
1
- import streamlit as st
2
- import tensorflow as tf
3
- import numpy as np
4
- from PIL import Image
5
- from tensorflow.keras import layers, Input, Model, Sequential
6
- from tensorflow.keras.applications.resnet_v2 import ResNet50V2, preprocess_input
7
-
8
- st.set_page_config(page_title="CIFAR-10 Final", layout="centered")
9
-
10
- @st.cache_resource
11
- def load_fixed_model():
12
- try:
13
- # 1. Define the Input
14
- img_input = Input(shape=(32, 32, 3), name="input_1")
15
-
16
- # 2. UpSampling (Layer 0)
17
- x = layers.UpSampling2D(size=(3, 3), name="up_sampling2d")(img_input)
18
-
19
- # 3. Augmentation (Layer 1) - We must use the same name as the notebook
20
- aug_layer = Sequential([
21
- layers.RandomFlip("horizontal"),
22
- layers.RandomRotation(0.1),
23
- layers.RandomZoom(0.1),
24
- ], name="sequential")
25
- x = aug_layer(x)
26
-
27
- # 4. ResNet50V2 Base (Layer 2)
28
- # We set weights=None so it doesn't download anything
29
- base_model = ResNet50V2(weights=None, include_top=False, input_shape=(96, 96, 3))
30
- x = base_model(x)
31
-
32
- # 5. The Head (Layers 3-7)
33
- x = layers.GlobalAveragePooling2D(name="global_average_pooling2d")(x)
34
- x = layers.BatchNormalization(name="batch_normalization")(x)
35
- x = layers.Dense(256, activation='relu', name="dense")(x)
36
- x = layers.Dropout(0.4, name="dropout")(x)
37
- predictions = layers.Dense(10, activation='softmax', name="dense_1")(x)
38
-
39
- # Create the model
40
- model = Model(inputs=img_input, outputs=predictions)
41
-
42
- # 6. THE FIX: Load by name
43
- # This ignores the 'layer index' and looks for 'resnet50v2', 'dense', etc.
44
- model.load_weights('cifar10_augtlmodel.h5', by_name=True, skip_mismatch=True)
45
- return model
46
- except Exception as e:
47
- st.error(f"Surgical Load Error: {e}")
48
- return None
49
-
50
- # --- UI LOGIC ---
51
- st.title("🚀 CIFAR-10 Classifier")
52
- st.write("Mode: Surgical Weight Mapping (Functional API)")
53
-
54
- model = load_fixed_model()
55
-
56
- uploaded_file = st.file_uploader("Upload Image", type=["jpg", "png", "jpeg"])
57
-
58
- if uploaded_file and model:
59
- image = Image.open(uploaded_file).convert('RGB')
60
- st.image(image, width=250)
61
-
62
- img_32 = image.resize((32, 32))
63
- x = np.array(img_32)
64
- x = np.expand_dims(x, axis=0)
65
- x = preprocess_input(x)
66
-
67
- if st.button('Predict'):
68
- preds = model.predict(x)
69
- labels = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer',
70
- 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
71
-
72
- idx = np.argmax(preds)
73
- st.success(f"Result: **{labels[idx]}** ({np.max(preds)*100:.2f}%)")