Spaces:
Running
Running
Commit
·
c67e806
1
Parent(s):
dfaea14
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,23 +72,25 @@ elif mode == "Train Mode":
|
|
| 72 |
# Label input
|
| 73 |
user_label = st.selectbox("Select the correct label", labels)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Train button
|
| 76 |
if st.button('Train Model'):
|
| 77 |
# Update the model with the user-provided image and label
|
| 78 |
-
target = np.zeros(len(labels))
|
| 79 |
-
target[labels.index(user_label)] = 1
|
| 80 |
-
|
| 81 |
# Reshape the image to match the model's input shape
|
| 82 |
image = tf.image.resize(image, (224, 224)) # adjust the size as needed
|
| 83 |
image = tf.expand_dims(image, axis=0)
|
| 84 |
-
|
| 85 |
# Create a dataset with the new image and label
|
| 86 |
dataset = tf.data.Dataset.from_tensor_slices((image, target))
|
| 87 |
dataset = dataset.batch(1) # Batch size 1 as we are using a single image
|
| 88 |
-
|
| 89 |
# Train the model
|
| 90 |
model.fit(dataset, epochs=1) # You might want to adjust the number of epochs
|
| 91 |
-
|
| 92 |
st.success(f'Model has been trained with the new image and label.')
|
| 93 |
-
except Exception as e:
|
| 94 |
-
st.error(f"An error occurred: {e}. Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")
|
|
|
|
| 72 |
# Label input
|
| 73 |
user_label = st.selectbox("Select the correct label", labels)
|
| 74 |
|
| 75 |
+
# Train button
|
| 76 |
+
# Inside the "Train Mode" section
|
| 77 |
+
|
| 78 |
+
|
| 79 |
# Train button
|
| 80 |
if st.button('Train Model'):
|
| 81 |
# Update the model with the user-provided image and label
|
| 82 |
+
target = np.zeros((1, len(labels))) # Adjust dimensions for one-hot encoding
|
| 83 |
+
target[0, labels.index(user_label)] = 1
|
| 84 |
+
|
| 85 |
# Reshape the image to match the model's input shape
|
| 86 |
image = tf.image.resize(image, (224, 224)) # adjust the size as needed
|
| 87 |
image = tf.expand_dims(image, axis=0)
|
| 88 |
+
|
| 89 |
# Create a dataset with the new image and label
|
| 90 |
dataset = tf.data.Dataset.from_tensor_slices((image, target))
|
| 91 |
dataset = dataset.batch(1) # Batch size 1 as we are using a single image
|
| 92 |
+
|
| 93 |
# Train the model
|
| 94 |
model.fit(dataset, epochs=1) # You might want to adjust the number of epochs
|
| 95 |
+
|
| 96 |
st.success(f'Model has been trained with the new image and label.')
|
|
|
|
|
|