Spaces:
Sleeping
Sleeping
Update vit_Training.py
Browse files- vit_Training.py +19 -8
vit_Training.py
CHANGED
|
@@ -64,16 +64,27 @@ class Custom_VIT_Model:
|
|
| 64 |
else:
|
| 65 |
self.df = pd.DataFrame(columns=['image_path', 'label'])
|
| 66 |
|
| 67 |
-
def add_data(self, image_path: str, label: int):
|
| 68 |
-
new_entry = pd.DataFrame({'image_path': [image_path], 'label': [label]})
|
| 69 |
-
self.df = pd.concat([self.df, new_entry], ignore_index=True)
|
| 70 |
-
self.df.to_csv(self.data_file, index=False)
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
if len(self.df) >= 100:
|
| 76 |
-
self.retrain_model()
|
| 77 |
|
| 78 |
def retrain_model(self):
|
| 79 |
# Shuffle and split the data
|
|
|
|
| 64 |
else:
|
| 65 |
self.df = pd.DataFrame(columns=['image_path', 'label'])
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
def add_data(self, image_path: str, label: int):
|
| 69 |
+
# Create a new DataFrame entry
|
| 70 |
+
new_entry = pd.DataFrame({'image_path': [image_path], 'label': [label]})
|
| 71 |
+
|
| 72 |
+
# Append the new entry to the existing DataFrame
|
| 73 |
+
self.df = pd.concat([self.df, new_entry], ignore_index=True)
|
| 74 |
+
|
| 75 |
+
# Save the updated DataFrame to the specified CSV file
|
| 76 |
+
self.df.to_csv(self.data_file, index=False)
|
| 77 |
+
|
| 78 |
+
# Print the current state of the training data for debugging
|
| 79 |
+
print("Current training data:")
|
| 80 |
+
print(self.df)
|
| 81 |
+
|
| 82 |
+
# Check if we have 100 images for retraining
|
| 83 |
+
if len(self.df) >= 100:
|
| 84 |
+
print("Retraining the model as we have enough data.")
|
| 85 |
+
self.retrain_model()
|
| 86 |
|
| 87 |
+
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def retrain_model(self):
|
| 90 |
# Shuffle and split the data
|