Skip to content

Commit

Permalink
updates to new Merge UI (not finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
0ssamaak0 committed May 29, 2023
1 parent 61fc9fd commit c9ebdf8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DLTA_AI_app/labelme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 1. MAJOR version when you make incompatible API changes;
# 2. MINOR version when you add functionality in a backwards-compatible manner;
# 3. PATCH version when you make backwards-compatible bug fixes.
__version__ = "1.0.1"
__version__ = "1.0.2"

QT4 = QT_VERSION[0] == "4"
QT5 = QT_VERSION[0] == "5"
Expand Down
4 changes: 2 additions & 2 deletions DLTA_AI_app/labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2764,10 +2764,10 @@ def model_explorer(self):
Open model explorer dialog to select or download models
"""
self._config = get_config()
model_explorer_dialog = utils.ModelExplorerDialog(self, self._config["mute"], helpers.notification)
model_explorer_dialog = utils.ModelExplorerDialog(self, self._config["mute"], helpers.notification, merge = False)
# make it fit its contents
model_explorer_dialog.adjustSize()
model_explorer_dialog.setMinimumWidth(model_explorer_dialog.table.width() * 1.905)
model_explorer_dialog.setMinimumWidth(model_explorer_dialog.table.width() * 1.5)
model_explorer_dialog.setMinimumHeight(model_explorer_dialog.table.rowHeight(0) * 10)
model_explorer_dialog.exec_()
self.update_saved_models_json()
Expand Down
51 changes: 37 additions & 14 deletions DLTA_AI_app/labelme/utils/model_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self, main_window=None, mute=None, notification=None, merge=False):
self.main_window = main_window
self.mute = mute
self.notification = notification
if not merge:
self.merge = merge
if not self.merge:
self.setWindowTitle("Model Explorer")
else:
self.setWindowTitle("Merge Models")
Expand All @@ -53,7 +54,7 @@ def __init__(self, main_window=None, mute=None, notification=None, merge=False):
layout = QVBoxLayout()
self.setLayout(layout)

if not merge:
if not self.merge:
# Set up the toolbar
toolbar = QToolBar()
layout.addWidget(toolbar)
Expand Down Expand Up @@ -102,20 +103,21 @@ def __init__(self, main_window=None, mute=None, notification=None, merge=False):
self.check_availability()

# Populate the table with default data
if not merge:
if not self.merge:
self.populate_table()
else:
self.populate_table(merge=True)
self.populate_table()

# Set up the submit and cancel buttons
button_layout = QHBoxLayout()
layout.addLayout(button_layout)

close_button = QPushButton("Close")
close_button = QPushButton("Ok")
close_button.clicked.connect(self.close)
# add side padding to the button
close_button.setFixedWidth(100)


# make the button in the middle of the layout, don't stretch
button_layout.addStretch()
button_layout.addWidget(close_button)
Expand All @@ -124,13 +126,10 @@ def __init__(self, main_window=None, mute=None, notification=None, merge=False):
# layout spacing
layout.setSpacing(10)

def populate_table(self, merge=False):
def populate_table(self):
"""
Populates the table with data from models_json.
Args:
merge (bool): If True, excludes SAM and YOLOv8 models from the table.
Returns:
None
"""
Expand All @@ -154,7 +153,7 @@ def populate_table(self, merge=False):
# Populate the table with data
row_count = 0
for model in models_json:
if merge:
if self.merge:
if model["Model"] == "SAM" or model["Model"] == "YOLOv8":
continue

Expand All @@ -167,8 +166,14 @@ def populate_table(self, merge=False):

# Select Model column
self.selected_model = (-1, -1, -1)
if self.merge:
self.selected_models = []
select_row_button = QPushButton("Select Model")
select_row_button.clicked.connect(self.select_model)

if not self.merge:
select_row_button.clicked.connect(self.select_model)
else:
select_row_button.clicked.connect(self.select_merge_models)

self.table.setContentsMargins(10, 10, 10, 10)
self.table.setCellWidget(row_count, 10, select_row_button)
Expand Down Expand Up @@ -198,7 +203,7 @@ def populate_table(self, merge=False):
# change text
select_row_button.setText("Select from SAM Toolbar")

if merge:
if self.merge:
available_text = self.table.item(row_count, 9)
try:
available_text = available_text.text()
Expand Down Expand Up @@ -260,9 +265,27 @@ def select_model(self):
row = index.row()
model_id = int(self.table.item(row, 0).text())
# Set the selected model as the model with this id
self.selected_model = models_json[model_id][
"Model Name"], models_json[model_id]["Config"], models_json[model_id]["Checkpoint"],
self.selected_model = models_json[model_id]["Model Name"], models_json[model_id]["Config"], models_json[model_id]["Checkpoint"],
self.accept()

def select_merge_models(self):
# Get the button that was clicked
sender = self.sender()
# Get the row index of the button in the table
index = self.table.indexAt(sender.pos())
# Get the model id from the row index
row = index.row()
model_id = int(self.table.item(row, 0).text())
# Check if the button is already selected
if sender.isChecked():
# Add the selected model to the list of selected models
self.selected_models.append([models_json[model_id]["Model Name"], models_json[model_id]["Config"], models_json[model_id]["Checkpoint"]])
else:
# Remove the selected model from the list of selected models
if [models_json[model_id]["Model Name"], models_json[model_id]["Config"], models_json[model_id]["Checkpoint"]] in self.selected_models:
self.selected_models.remove([models_json[model_id]["Model Name"], models_json[model_id]["Config"], models_json[model_id]["Checkpoint"]])
print(self.selected_models)
return self.selected_models

def download_model(self, id):
"""
Expand Down

0 comments on commit c9ebdf8

Please sign in to comment.