Icon Filter

Der Icon-Steuerungsfilter ist eine Methode, um Steuerungen basierend auf der Ähnlichkeit zwischen dem Icon-Bild der Steuerung und dem Plan des Agenten mithilfe von Bild-/Text-Embeddings zu filtern.

Konfiguration

Um die Icon-Steuerungsfilterung zu aktivieren, müssen Sie ICON zur Liste CONTROL_FILTER in der Datei config_dev.yaml hinzufügen. Nachfolgend finden Sie die detaillierte Konfiguration des Icon-Steuerungsfilters in der Datei config_dev.yaml.

  • CONTROL_FILTER: Eine Liste von Filtermethoden, die Sie auf die Steuerungen anwenden möchten. Um die Icon-Steuerungsfilterung zu aktivieren, fügen Sie ICON zur Liste hinzu.
  • CONTROL_FILTER_TOP_K_ICON: Die Anzahl der Steuerungen, die nach dem Filtern beibehalten werden sollen.
  • CONTROL_FILTER_MODEL_ICON_NAME: Der Name des Steuerungsfiltermodells für die Icon-Ähnlichkeit. Standardmäßig ist es auf "clip-ViT-B-32" gesetzt.

Referenz

Basiert auf: BasicControlFilter

Eine Klasse, die ein Icon-Modell für die Steuerungsfilterung darstellt.

control_filter(control_dicts, cropped_icons_dict, plans, top_k)

Filtert Steuerungselemente basierend auf ihren Scores und gibt die Top-k Elemente zurück.

Parameter
  • control_dicts

    Das Wörterbuch aller Steuerungselemente.

  • cropped_icons_dict

    Das Wörterbuch der zugeschnittenen Icons.

  • plans

    Die Pläne, mit denen die Steuerung-Icons verglichen werden sollen.

  • top_k

    Die Anzahl der zurückzugebenden Top-Elemente.

Rückgabe
  • Die Liste der Top-k Steuerungselemente basierend auf ihren Scores.

Quellcode in automator/ui_control/control_filter.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
def control_filter(self, control_dicts, cropped_icons_dict, plans, top_k):
    """
    Filters control items based on their scores and returns the top-k items.
    :param control_dicts: The dictionary of all control items.
    :param cropped_icons_dict: The dictionary of the cropped icons.
    :param plans: The plans to compare the control icons against.
    :param top_k: The number of top items to return.
    :return: The list of top-k control items based on their scores.
    """

    scores_items = []
    filtered_control_dict = {}

    for label, cropped_icon in cropped_icons_dict.items():
        score = self.control_filter_score(cropped_icon, plans)
        scores_items.append((score, label))
    topk_scores_items = heapq.nlargest(top_k, scores_items, key=lambda x: x[0])
    topk_labels = [scores_items[1] for scores_items in topk_scores_items]

    for label, control_item in control_dicts.items():
        if label in topk_labels:
            filtered_control_dict[label] = control_item
    return filtered_control_dict

control_filter_score(control_icon, plans)

Berechnet den Score eines Steuerung-Icons basierend auf seiner Ähnlichkeit mit den gegebenen Schlüsselwörtern.

Parameter
  • control_icon

    Das Steuerung-Icon-Bild.

  • plans

    Der Plan, mit dem das Steuerung-Icon verglichen werden soll.

Rückgabe
  • Der maximale Ähnlichkeits-Score zwischen dem Steuerung-Icon und den Schlüsselwörtern.

Quellcode in automator/ui_control/control_filter.py
240
241
242
243
244
245
246
247
248
249
250
def control_filter_score(self, control_icon, plans):
    """
    Calculates the score of a control icon based on its similarity to the given keywords.
    :param control_icon: The control icon image.
    :param plans: The plan to compare the control icon against.
    :return: The maximum similarity score between the control icon and the keywords.
    """

    plans_embedding = self.get_embedding(plans)
    control_icon_embedding = self.get_embedding(control_icon)
    return max(self.cos_sim(control_icon_embedding, plans_embedding).tolist()[0])