Beispiel #1
0
    def add_word(self):
        name = self.lineEdit_Item.text()
        if name != "" and len(self.treeViewLibrary.selectedIndexes()) > 0:
            selected = self.vocabulary_model_library.itemFromIndex(self.treeViewLibrary.selectedIndexes()[0])
            selected_item = selected.voc_object

            item = None
            if selected_item.get_type() == VOCABULARY_WORD:
                word = selected_item.vocabulary.create_word(name, selected_item.name)

                if word is not None:
                    item = VocabularyItem(word.name, word)
                else:
                    msg = QMessageBox.warning(self, "Duplicate Word",
                                              "Adding two words with the same name is not allowed.")
            elif selected_item.get_type() == VOCABULARY:
                word = selected_item.create_word(name)

                if word is not None:
                    item = VocabularyItem(word.name, word)
                else:
                    msg = QMessageBox.warning(self, "Duplicate Word",
                                              "Adding two words with the same name is not allowed.")
            else:
                log_error("Failed to create word")
                item = None

            if item is not None:
                index = self.add_to_tree(selected, item)
                self.treeViewLibrary.scrollTo(index)
        self.lineEdit_Item.setText("")
Beispiel #2
0
 def on_remove_script(self):
     for script in self.scripts:
         try:
             self.project.remove_script(script)
         except Exception as e:
             log_error("ContextMenu Error", e)
             continue
Beispiel #3
0
    def remove_project(self,
                       project: VIANProject = None,
                       file=None,
                       delete_from_disk=False):
        """
        Removes a project from the corpus, can either be given by VIANProject object or file.
        :param project:
        :param file:
        :param delete_from_disk:
        :return:
        """
        if project is None and file is None:
            raise ValueError("Either project or file has to be given.")
        if project is None:
            project = VIANProject().load_project(file)
        if project.uuid in self.project_paths:
            self.project_paths.pop(project.uuid)
        if project.uuid in self.projects_loaded:
            self.projects_loaded.pop(project.uuid)
        project.close()

        print(self.projects_loaded, self.project_paths)
        if delete_from_disk:
            project.close()
            pdir = project.folder
            try:
                if os.path.isdir(pdir):
                    rmtree(pdir)
            except Exception as e:
                log_error("Could not remove project", e)

        self.onProjectRemoved.emit(project)
Beispiel #4
0
    def remove_color(self, c):
        try:
            self.recent_colors.remove(c)
        except Exception as e:
            log_error(e)

        self.update_widgets()
Beispiel #5
0
    def on_ok(self):
        if self.script is None:
            with open("data/default_pipeline.py", "r") as f:
                script = f.read()

            script = script.replace("%PIPELINE_NAME%",
                                    self.lineEdit_Name.text().replace(" ", ""))
            script = script.replace(
                "%AUTHOR%",
                self.lineEdit_Author.text().replace(" ", ""))
            script = script.replace("%UUID%", str(uuid4()))
        else:
            script = self.script

        pipeline_script = self.main_window.project.create_pipeline_script(
            name=self.lineEdit_Name.text().replace(" ", ""),
            author=self.lineEdit_Author.text().replace(" ", ""),
            script=script)
        try:
            self.parent().pipeline_script = pipeline_script
            self.parent().editor.setPlainText(pipeline_script.script)
            self.parent().reload()
            self.close()
        except Exception as e:
            log_error("NewScriptDialog", e)
            pass
Beispiel #6
0
    def extract(self):
        self.audioExtractingStarted.emit()
        with HDF5_FILE_LOCK:
            self._read(self.project.movie_descriptor.get_movie_path())
            self.audio_samples = self._sample_audio(self.callback)
            if self.audio_samples is None:
                return
            self.audio_volume = np.abs(np.mean(self.audio_samples, axis=1))

            log_info("Size", self.audio_samples.nbytes / 10**6)
            log_info("Size", self.audio_volume.nbytes / 10**6)
            project_audio_path = os.path.join(self.project.data_dir,
                                              "audio.mp3")
            self.audioProcessed.emit(
                TimelineDataset("Audio Volume",
                                self.audio_volume,
                                ms_to_idx=(self.resolution * 1000),
                                vis_type=TimelineDataset.VIS_TYPE_AREA))
            try:
                if not os.path.isfile(
                        project_audio_path) and self.export_audio:
                    self._audioclip.write_audiofile(
                        os.path.join(self.project.data_dir, "audio.mp3"))
            except Exception as e:
                log_error(e)
            self._videoclip.close()
            self._audioclip.close()
        self.audioExtractingEnded.emit()
 def on_set_main(self):
     self.hide()
     try:
         self.segmentation[0].project.set_main_segmentation(self.segmentation[0])
     except Exception as e:
             log_error("ContextMenu Error", e)
     self.close()
Beispiel #8
0
 def on_delete(self):
     try:
         for obj in self.media_object:
             obj.container.remove_media_object(obj)
     except Exception as e:
         log_error(e)
         pass
Beispiel #9
0
    def add_project(self,
                    project: VIANProject = None,
                    file=None,
                    merge_behaviour=MERGE_BEHAVIOUR_MERGE_KEEP):
        """
        Adds a project to the corpus, can either be given by VIANProject object or file
        :param project:
        :param file:
        :return:
        """
        if project is None and file is None:
            raise ValueError("Either project or file has to be given.")
        if project is None:
            results = None
            try:
                project = VIANProject().load_project(file)
                t_exp_names = [e.name for e in self.template.experiments]
                t_exp_unique_ids = [
                    e.unique_id for e in self.template.experiments
                ]

                template_dict = self.template.get_template(segm=True,
                                                           voc=True,
                                                           ann=True,
                                                           scripts=False,
                                                           experiment=True,
                                                           pipeline=True)

                if merge_behaviour == self.MERGE_BEHAVIOUR_DELETE_DELETE:
                    to_remove = [
                        e for e in project.experiments if e.name in t_exp_names
                        or e.unique_id in t_exp_unique_ids
                    ]
                    for t in to_remove:
                        project.remove_experiment(t)
                    results = project.apply_template(template=template_dict)

                elif merge_behaviour == self.MERGE_BEHAVIOUR_MERGE_DELETE:
                    results = project.apply_template(template=template_dict,
                                                     merge=True,
                                                     merge_drop=True)

                elif merge_behaviour == self.MERGE_BEHAVIOUR_MERGE_KEEP:
                    results = project.apply_template(template=template_dict,
                                                     merge=True,
                                                     merge_drop=False)

            except Exception as e:
                log_error("Could not load project", e)
                return
            project.store_project()
            project.close()

            for l in results:
                log_info(l)

            self.projects_loaded[project.uuid] = project
            self.project_paths[project.uuid] = project.path
            self.onProjectAdded.emit(project)
 def on_subs_changed(self, index):
     try:
         if len(self.subs) > 0:
             self.main_window.player.set_subtitle(self.subs[index][0])
     except Exception as e:
         log_error(
             "PlayerControls.on_subs_changed(): Could not set Subtitles:",
             e)
Beispiel #11
0
 def plot_time_palette(self, data):
     try:
         self.time_palette.set_palette(data[0], data[1])
         self.time_palette.draw_palette()
     except Exception as e:
         log_error(
             "Exception in ColorimetryLiveWidget::plot_time_palette()", e)
         pass
Beispiel #12
0
 def on_delete(self):
     self.hide()
     for s in self.segments:
         try:
             s.project.remove_segment(s)
         except Exception as e:
             log_error("ContextMenu Error", e)
             continue
     self.close()
Beispiel #13
0
 def on_delete(self):
     self.hide()
     for a in self.annotation:
         try:
             a.project.remove_annotation(a)
         except Exception as e:
             log_error("ContextMenu Error", e)
             continue
     self.close()
Beispiel #14
0
 def on_delete(self):
     self.hide()
     for l in self.layer:
         try:
             l.project.remove_annotation_layer(l)
         except Exception as e:
             log_error("ContextMenu Error", e)
             continue
     self.close()
Beispiel #15
0
 def toggle_timeline_visiblity(self):
     self.hide()
     visibility = not self.segmentation[0].timeline_visibility
     for s in self.segmentation:
         try:
             s.set_timeline_visibility(visibility)
         except Exception as e:
             log_error("ContextMenu Error", e)
             continue
Beispiel #16
0
 def on_visibility_changed(self, visibility):
     if visibility:
         if self.main_window.project is not None:
             try:
                 data = self.main_window.project.colormetry_analysis.get_update(
                     self.main_window.player.get_media_time())
                 self.update_timestep(data, None)
             except Exception as e:
                 log_error("Visibility Changed Exception", e)
Beispiel #17
0
 def _run_task(self, task_id, analysis, args, on_progress):
     log_info("Running Analysis", analysis.__class__)
     try:
         return analysis.process(args, on_progress)
     except Exception as e:
         traceback.print_exc()
         exctype, value = sys.exc_info()[:2]
         log_error(traceback.print_exc())
         self.signals.sign_error.emit((exctype, value, traceback.format_exc()))
         return None
Beispiel #18
0
    def remove_keys(self):
        self.hide()
        for a in self.annotation:
            try:
                a.remove_keys()
            except Exception as e:
                log_error("ContextMenu Error", e)
                continue

        self.close()
Beispiel #19
0
    def go_to(self):
        try:
            self.hide()
            last = self.screenshots[len(self.screenshots) - 1]
            self.main_window.player.pause()
            self.main_window.player.set_media_time(last.movie_timestamp)
        except Exception as e:
            log_error("ContextMenu Error", e)

        self.close()
Beispiel #20
0
 def toggle_lock(self):
     self.hide()
     new_status = not self.segmentation[0].is_locked()
     for s in self.segmentation:
         try:
             if new_status:
                 s.lock()
             else:
                 s.unlock()
         except Exception as e:
             log_error("ContextMenu Error", e)
             continue
Beispiel #21
0
    def get_fields(self, path, delimiter = ";"):
        self.delimiter = delimiter

        try:
            with open(path, 'r') as csvfile:
                reader = csv.reader((line.replace('\0','') for line in csvfile) , delimiter=delimiter)
                for row in reader:

                    return True, row
        except Exception as e:
            log_error(e)
            return False, []
    def run_selection(self):
        if self.project is not None:
            if self.main_window.vian_event_handler.current_pipeline is None:
                return

            container = self.project.selected

            scrs = [s for s in container if isinstance(s, Screenshot)]
            segments = [s for s in container if isinstance(s, Segment)]
            annotations = [s for s in container if isinstance(s, Annotation)]

            missing_info = self.project.get_missing_analyses(
                self.main_window.vian_event_handler.current_pipeline.
                requirements,
                screenshots=scrs,
                annotations=annotations,
                segments=segments)
            missing = dict()

            log_info("## Missing Analyses in Pipeline ##")
            for k in missing_info.keys():
                # print(k, missing_info[k], missing.items())
                missing[k] = missing_info[k][0]
                log_info("## -- ", k, missing_info[k][2], missing_info[k][1],
                         missing_info[k][0])

            experiment = self.main_window.vian_event_handler.current_pipeline.experiment

            if experiment is None:
                log_error("Experiment not found for RunAll")
                return
            for cl in missing.keys():
                for priority in sorted(missing[cl].keys()):
                    for analysis_name in missing[cl][priority].keys():
                        analysis = self.main_window.eval_class(analysis_name)
                        for clobj_name, containers in missing[cl][priority][
                                analysis_name].items():
                            clobj = experiment.get_classification_object_by_name(
                                clobj_name)

                            if clobj is None:
                                log_warning("Classification Object not found")
                                continue
                            d = dict(analysis=analysis(),
                                     targets=containers,
                                     parameters=None,
                                     classification_objs=clobj)
                            log_info("Pipeline Analysis: ", priority,
                                     analysis_name, clobj_name)
                            self.onRunAnalysis.emit(d)
 def on_selected(self, sender, selected):
     try:
         if not self.dock_widget_visible:
             return
         if len(selected) > 0:
             if isinstance(selected[0], IAnalysisJobAnalysis):
                 self.activate_analysis(selected[0])
             elif isinstance(selected[0], Experiment):
                 self.activate_classification(selected[0])
             else:
                 self.activate_selector(selected)
     except Exception as e:
         log_error(e)
         pass
    def set_palettes(self, palettes):
        try:
            self.palette_tree = np.vstack(tuple(palettes.copy()))
        except Exception as e:
            log_error("Exception in set_palettes()", palettes)
            return
        layers = self.palette_tree[:, 1]
        if self.slider is not None:
            self.slider.setRange(0, len(np.unique(layers)) - 1)
            if self.spbox_depth is not None:
                self.spbox_depth.setRange(0, len(np.unique(layers)) - 1)

        if not (0 <= self.depth <= len(np.unique(layers)) - 1):
            self.depth = len(np.unique(layers)) - 1
        self.draw_palette()
Beispiel #25
0
    def on_settings_changed(self):
        if self.checkBox_UseLocation.isChecked():
            try:
                splitted = self.preview_path.split(
                    self.lineEdit_Delimiter.text())

                idx_h = self.sB_PositionTimeH.value() - 1
                idx_m = self.sB_PositionTimeM.value() - 1
                idx_s = self.sB_PositionTimeS.value() - 1
                idx_ms = self.sB_PositionTimeMS.value() - 1
                idx_segment = self.sB_PositionSegment.value() - 1
                text = ""
                text_full = ""
                # IF has time location
                if (idx_h >= 0 or idx_m >= 0 or idx_s >= 0 or idx_ms >= 0):
                    if (idx_h >= 0 and idx_h < len(splitted)):
                        text += "H = " + str(splitted[idx_h])

                    if (idx_m >= 0 and idx_m < len(splitted)):
                        text += "  M = " + str(splitted[idx_m])

                    if (idx_s >= 0 and idx_s < len(splitted)):
                        text += "  S = " + str(splitted[idx_s])

                    if (idx_ms >= 0 and idx_ms < len(splitted)):
                        text += "  MS = " + str(splitted[idx_ms])
                else:
                    if (idx_segment >= 0 and idx_h < len(splitted)):
                        text += "  SEGM_ID = " + str(splitted[idx_segment])

                for i, t in enumerate(splitted):
                    if i not in [idx_h, idx_s, idx_m, idx_ms, idx_segment]:
                        text_full += (str(t))
                    else:
                        text_full += ("[" + str(t) + "]")
                    if i < len(splitted) - 1:
                        text_full += " _ "
                self.label_P0.setText(text)
                self.label_P0.setVisible(True)
                self.label_P1.setText(text_full)
                self.label_P1.setVisible(True)
            except Exception as e:
                log_error(e)

        else:
            self.label_P0.setVisible(False)
            self.label_P1.setVisible(False)
 def set_project(self, project:VIANProject):
     if project is not None:
         self.lineEdit_Name.setText(project.name)
         self.lbl_Location.setText(project.path)
         self.goto_dir = project.folder
         try:
             self.spinBox_ItemID.setValue(int(project.movie_descriptor.movie_id.split("_")[0]))
             self.spinBox_ManifestationID.setValue(int(project.movie_descriptor.movie_id.split("_")[1]))
             self.spinBox_CopyID.setValue(int(project.movie_descriptor.movie_id.split("_")[2]))
         except Exception as e:
             log_error(e)
     else:
         self.lineEdit_Name.setText("")
         self.lbl_Location.setText("")
         self.goto_dir = None
         self.spinBox_ItemID.setValue(0)
         self.spinBox_ManifestationID.setValue(0)
         self.spinBox_CopyID.setValue(0)
Beispiel #27
0
    def work(self, data):
        if data is not None:
            self.is_drawing = True
            try:
                if self.palette.isVisible():
                    self.palette.set_palette(data['palette'])
                    self.palette.draw_palette()

                if self.lab_palette.isVisible():
                    self.lab_palette.set_palette(data['palette'])
                    self.lab_palette.draw_palette()

                if self.hilbert_vis.isVisible():
                    self.hilbert_vis.plot_color_histogram(data['histogram'])

            except Exception as e:
                log_error("Exception in ColormetryWidget.update_timestep()",
                          str(e))
            self.is_drawing = False
    def deserialize(self, serialization, project):
        self.project = project
        self.ID = serialization["scene_id"]
        self.unique_id = serialization['unique_id']
        self.start = serialization["start"]
        self.end = serialization["end"]
        self.duration = serialization["duration"]

        self.notes = serialization['notes']

        # Backwards Compatibility
        if 'name' in serialization:
            self.name = serialization['name']
        else:
            self.name = str(self.ID)

        if 'locked' in serialization:
            self.locked = serialization['locked']
        else:
            self.locked = False

        if 'annotation_body' in serialization:
            self.annotation_body = serialization['annotation_body']
        else:
            self.annotation_body = ""

        try:
            for w in serialization["media_objects"]:
                o_type = w['dtype']
                if o_type in [
                        MediaObjectType.HYPERLINK, MediaObjectType.SOURCE
                ]:
                    new = DataMediaObject(None, None, self,
                                          None).deserialize(w)
                else:
                    new = FileMediaObject(None, None, self,
                                          None).deserialize(w)
                new.set_project(self.project)
                self.media_objects.append(new)
        except Exception as e:
            log_error(e)

        return self
Beispiel #29
0
    def load_pipelines(self, ddir="extensions/pipelines/"):
        file_list = []
        # print (os.path.abspath(os.path.curdir))
        for root, dirs, files in os.walk(ddir, topdown=False):
            for name in files:
                if "py" in name:
                    path = os.path.join(root, name)
                    path = path.replace("\\", "/")
                    path = path.replace(".py", "")
                    path = path.replace("/", ".")
                    if not "__init__" in path and not "__pycache__" in path:
                        file_list.append(path)

        for f in file_list:
            try:
                importlib.import_module(f)
            except Exception as e:
                log_error("Exception in load_pipelines():", e)
                continue
    def __init__(self):
        super(ERCFilmColorsVIANPipeline, self).__init__()
        try:
            self.graph = tf.Graph()
            config = tf.ConfigProto()
            config.gpu_options.allow_growth = True  # dynamically grow the memory used on the GPU
            config.gpu_options.per_process_gpu_memory_fraction = 0.4

            with self.graph.as_default():
                self.session = tf.Session(config=config)
                KTF.set_session(self.session)
                self.model = PSPNetModelVIAN(input_shape=(512, 512, 3))
                self.model.load_weights(KERAS_LIP_WEIGHTS)
                self.model_name = DATASET_NAME_LIP
        except Exception as e:
            log_error(e)
            self.model = None
            self.model_name = "LIP"
            self.session = None
        log_info(self.model, self.model_name)