Update app.py
Browse files
app.py
CHANGED
|
@@ -240,10 +240,46 @@ def update_class_counts_handler(class_df, dataset_info):
|
|
| 240 |
for _, row in class_df.iterrows():
|
| 241 |
if not row["Remove"]:
|
| 242 |
rename_to = row["Rename To"]
|
| 243 |
-
#
|
| 244 |
-
|
|
|
|
| 245 |
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
return summary_df
|
| 248 |
|
| 249 |
def finalize_handler(dataset_info, class_df, progress=gr.Progress()):
|
|
@@ -256,7 +292,6 @@ def finalize_handler(dataset_info, class_df, progress=gr.Progress()):
|
|
| 256 |
for _, row in class_df.iterrows():
|
| 257 |
if not row["Remove"]:
|
| 258 |
rename_to = row["Rename To"]
|
| 259 |
-
# The limit for a merged class is the sum of the limits of its constituents
|
| 260 |
class_limits[rename_to] = class_limits.get(rename_to, 0) + int(row["Max Images"])
|
| 261 |
|
| 262 |
status, path = finalize_merged_dataset(dataset_info, class_mapping, class_limits, progress)
|
|
@@ -415,7 +450,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="sky")) as app:
|
|
| 415 |
epochs_sl = gr.Slider(1, 500, 100, step=1, label="Epochs")
|
| 416 |
batch_sl = gr.Slider(1, 32, 8, step=1, label="Batch Size")
|
| 417 |
imgsz_num = gr.Number(label="Image Size", value=640)
|
| 418 |
-
|
|
|
|
| 419 |
opt_dd = gr.Dropdown(["Adam", "AdamW", "SGD"], value="Adam", label="Optimizer")
|
| 420 |
train_btn = gr.Button("Start Training", variant="primary")
|
| 421 |
with gr.Column(scale=2):
|
|
|
|
| 240 |
for _, row in class_df.iterrows():
|
| 241 |
if not row["Remove"]:
|
| 242 |
rename_to = row["Rename To"]
|
| 243 |
+
# This logic needs to be careful: sum counts of all original classes that map to the same `rename_to`
|
| 244 |
+
# Let's recalculate based on mapping
|
| 245 |
+
merged_summary[rename_to] = 0 # reset
|
| 246 |
|
| 247 |
+
for original_name, rename_to in class_mapping.items():
|
| 248 |
+
if rename_to in merged_summary:
|
| 249 |
+
# find count for original name in its original mapped state
|
| 250 |
+
original_count = gather_class_counts(dataset_info, {k:k for k in class_mapping.keys()}).get(original_name,0)
|
| 251 |
+
is_removed = class_df.loc[class_df['Original Name'] == original_name, 'Remove'].iloc[0]
|
| 252 |
+
if not is_removed:
|
| 253 |
+
merged_summary[rename_to] += original_count
|
| 254 |
+
|
| 255 |
+
final_summary = {}
|
| 256 |
+
# Recalculate from scratch for simplicity and accuracy
|
| 257 |
+
class_map_for_summary = dict(zip(class_df["Original Name"], class_df["Rename To"]))
|
| 258 |
+
all_final_names = set(class_df[~class_df['Remove']]['Rename To'])
|
| 259 |
+
|
| 260 |
+
final_counts = {name: 0 for name in all_final_names}
|
| 261 |
+
|
| 262 |
+
for loc, names, splits, _ in dataset_info:
|
| 263 |
+
for split in splits:
|
| 264 |
+
labels_dir = os.path.join(loc, split, 'labels')
|
| 265 |
+
if not os.path.exists(labels_dir): continue
|
| 266 |
+
for label_file in os.listdir(labels_dir):
|
| 267 |
+
found_in_file = set()
|
| 268 |
+
with open(os.path.join(labels_dir, label_file), 'r') as f:
|
| 269 |
+
for line in f:
|
| 270 |
+
try:
|
| 271 |
+
class_id = int(line.split()[0])
|
| 272 |
+
original_name = names[class_id]
|
| 273 |
+
is_removed = class_df.loc[class_df['Original Name'] == original_name, 'Remove'].iloc[0]
|
| 274 |
+
if not is_removed:
|
| 275 |
+
mapped_name = class_map_for_summary.get(original_name)
|
| 276 |
+
if mapped_name:
|
| 277 |
+
found_in_file.add(mapped_name)
|
| 278 |
+
except (ValueError, IndexError, KeyError): continue
|
| 279 |
+
for cls in found_in_file:
|
| 280 |
+
final_counts[cls] += 1
|
| 281 |
+
|
| 282 |
+
summary_df = pd.DataFrame(list(final_counts.items()), columns=["Final Class Name", "Est. Total Images"])
|
| 283 |
return summary_df
|
| 284 |
|
| 285 |
def finalize_handler(dataset_info, class_df, progress=gr.Progress()):
|
|
|
|
| 292 |
for _, row in class_df.iterrows():
|
| 293 |
if not row["Remove"]:
|
| 294 |
rename_to = row["Rename To"]
|
|
|
|
| 295 |
class_limits[rename_to] = class_limits.get(rename_to, 0) + int(row["Max Images"])
|
| 296 |
|
| 297 |
status, path = finalize_merged_dataset(dataset_info, class_mapping, class_limits, progress)
|
|
|
|
| 450 |
epochs_sl = gr.Slider(1, 500, 100, step=1, label="Epochs")
|
| 451 |
batch_sl = gr.Slider(1, 32, 8, step=1, label="Batch Size")
|
| 452 |
imgsz_num = gr.Number(label="Image Size", value=640)
|
| 453 |
+
# <<< FIXED: Removed the 'format' argument which is not supported.
|
| 454 |
+
lr_num = gr.Number(label="Learning Rate", value=0.001)
|
| 455 |
opt_dd = gr.Dropdown(["Adam", "AdamW", "SGD"], value="Adam", label="Optimizer")
|
| 456 |
train_btn = gr.Button("Start Training", variant="primary")
|
| 457 |
with gr.Column(scale=2):
|