Exemple #1
0
    def _start_btn_eh(self):

        if self._first_start:
            self._first_start = False

            self._train_session_details_input.destroy()
            self._train_sess_save_details.destroy()
            self._data_augmentation.destroy()

            self._create_and_place_output_frame_and_canvas()

            self._fold_number_input = ComboboxInputF(
                parent=self._sc_scrollable.f_main_frame,
                user_instruction=const.KFCVESG_K_TEXT,
                user_options=self._display_options,
                selection_eh=self._fold_number_selected_eh,
            )

            self._fold_number_input.config(pady=30)

            self._train_session_output = TrainSessOutputF(
                parent=self._sc_scrollable.f_main_frame, )

            self._test_sess_output = TestSessOutputF(
                parent=self._sc_scrollable.f_main_frame)

            self._test_sess_output.progress_bar.pack_forget()

            self._fold_number_input.pack(side='top', fill='both', expand=True)

            self._train_session_output.pack(side='top',
                                            fill='both',
                                            expand=True)

            self._test_sess_output.pack(side='top', fill='both', expand=True)

            # TODO -> Call the controller to start the training session.

            from utils.call_method_in_new_thread import CallMethodInNewThread

            CallMethodInNewThread.call_method(
                function_to_call=self.mock_data_set_creation, )
Exemple #2
0
    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,

            font=const.TESC_TITLE_FONT,
            text=const.TESC_TITLE_TEXT,

            padx=const.TESC_TITLE_PADX,
            pady=const.TESC_TITLE_PADY,
        )

        self._f_output = tk.Frame(
            self,

            relief=const.TESC_SUBFRAME_RELIEF,
            padx=const.TESC_SUBFRAME_PADX,
            pady=const.TESC_SUBFRAME_PADY,
            bd=const.TESC_SUBFRAME_BD,
        )

        self._f_chart = tk.Frame(
            self._f_output,
        )

        self._ci_chart_to_display = ComboboxInputF(
            parent=self._f_output,

            user_instruction=const.TESC_CHARTS_TEXT,
            user_options=const.TESC_CHARTS_OPTIONS,

            selection_eh=self._chart_selected_eh,
        )

        self._column_chart = ColumnChart(
            parent=self._f_chart
        )
    def _add_new_entry(self, class_name: str):
        """
        - Adds and displays a new input entry.
        """

        length = len(self._ci_correlations_input)

        number_of_identifiers = len(self._identifiers)
        number_of_classes = len(self._classes)

        if number_of_classes == number_of_identifiers:
            self._ci_correlations_input.append(
                ComboboxInputF(parent=self._f_main_frame,
                               user_instruction=class_name,
                               user_options=self._identifiers_left,
                               selection_eh=self._identifier_selected,
                               disabled=False))

            # Widget placement
            self._ci_correlations_input[length].pack(side='top',
                                                     fill='x',
                                                     expand=True)
Exemple #4
0
    def _create_widgets(self):

        self._create_and_place_output_frame_and_canvas()

        self._data_set_browse = ValidatedBrowseF(
            self._sc_scrollable.f_main_frame,

            no_selection_message=const.ETS_DSB_NO_SELECTION,
            user_instruction=const.ETS_DSB_USER_INSTRUCTION,
            invalid_message=const.ETS_DSB_INVALID_MESSAGE,

            browse_window_title=const.ETS_DSB_WINDOW_TITLE,
            initial_directory=const.ETS_DSB_INITIAL_DIRECTORY,
            supported_files=const.ETS_DSB_SUPPORTED_FILES,

            validation_method=self._validate_data_set_selection,

            browse_button_eh=self._data_set_selected_eh,

            directory=False,
            disabled=True
        )

        self._number_of_epochs_input = ComboboxInputF(
            self._sc_scrollable.f_main_frame,

            user_instruction=const.ETS_EPOCHS_NBR_TEXT,
            user_options=const.ETS_EPOCHS_NBR_OPTIONS,

            selection_eh=self._number_of_epochs_selected_eh,

            disabled=True
        )

        self._train_sess_details_output = TrainSessDetailsOutputF(
            parent=self._sc_scrollable.f_main_frame,

            disabled=True
        )

        self._train_sess_browse = BrowseF(
            self._sc_scrollable.f_main_frame,

            no_selection_message=const.ETS_TSB_NO_SELECTION,
            user_instruction=const.ETS_TSB_USER_INSTRUCTION,
            browse_window_title=const.ETS_TSB_WINDOW_TITLE,
            initial_path=const.ETS_TSB_INITIAL_DIRECTORY,
            supported_files=const.ETS_TSB_SUPPORTED_FILES,

            browse_button_eh=self._train_session_selected_eh,

            directory=False,
            disabled=False
        )

        self._session_buttons = SessionButtonsF(
            parent=self._sc_scrollable.f_main_frame,

            start_eh=self._start_btn_eh,
            pause_eh=self._pause_btn_eh,
            stop_eh=self._stop_btn_eh,
            cancel_eh=self._cancel_btn_eh,

            disabled=True
        )

        self._train_sess_browse.config(
            pady=const.ETS_FRAME_PADY * 4,
        )

        self._session_buttons.config(
            pady=const.ETS_FRAME_PADY * 4,
        )

        # TODO

        """
Exemple #5
0
class ExistentTrainSessGUI(tk.Frame):

    def __init__(self,

                 parent,

                 enable_train_sess_buttons,
                 disable_train_sess_buttons):

        tk.Frame.__init__(self,
                          parent,
                          bg='light green')

        self._enable_train_sess_buttons = enable_train_sess_buttons
        self._disable_train_sess_buttons = disable_train_sess_buttons

        self._number_of_epochs_selected = False
        self._valid_data_set_selected = False
        self._train_session_selected = False
        self._test_data_set_path = ''
        self._first_start = True

        self._train_session = None

        self._sc_scrollable = None
        self._f_output = None

        self._create_widgets()
        self._place_widgets()

    #########################################################################
    # Widget creation and placement

    def _create_and_place_output_frame_and_canvas(self):

        if self._sc_scrollable:
            self._sc_scrollable.destroy()
            del self._sc_scrollable

        if self._f_output:
            self._f_output.destroy()
            del self._f_output

        self._f_output = tk.Frame(
            self,
        )

        self._sc_scrollable = ScrollableCanvasC(
            parent=self._f_output,
        )

        self._sc_scrollable.pack(side='top',
                                 fill='both',
                                 expand=True)

        self._f_output.pack(side='top',
                            fill='both',
                            expand=True)

    def _create_widgets(self):

        self._create_and_place_output_frame_and_canvas()

        self._data_set_browse = ValidatedBrowseF(
            self._sc_scrollable.f_main_frame,

            no_selection_message=const.ETS_DSB_NO_SELECTION,
            user_instruction=const.ETS_DSB_USER_INSTRUCTION,
            invalid_message=const.ETS_DSB_INVALID_MESSAGE,

            browse_window_title=const.ETS_DSB_WINDOW_TITLE,
            initial_directory=const.ETS_DSB_INITIAL_DIRECTORY,
            supported_files=const.ETS_DSB_SUPPORTED_FILES,

            validation_method=self._validate_data_set_selection,

            browse_button_eh=self._data_set_selected_eh,

            directory=False,
            disabled=True
        )

        self._number_of_epochs_input = ComboboxInputF(
            self._sc_scrollable.f_main_frame,

            user_instruction=const.ETS_EPOCHS_NBR_TEXT,
            user_options=const.ETS_EPOCHS_NBR_OPTIONS,

            selection_eh=self._number_of_epochs_selected_eh,

            disabled=True
        )

        self._train_sess_details_output = TrainSessDetailsOutputF(
            parent=self._sc_scrollable.f_main_frame,

            disabled=True
        )

        self._train_sess_browse = BrowseF(
            self._sc_scrollable.f_main_frame,

            no_selection_message=const.ETS_TSB_NO_SELECTION,
            user_instruction=const.ETS_TSB_USER_INSTRUCTION,
            browse_window_title=const.ETS_TSB_WINDOW_TITLE,
            initial_path=const.ETS_TSB_INITIAL_DIRECTORY,
            supported_files=const.ETS_TSB_SUPPORTED_FILES,

            browse_button_eh=self._train_session_selected_eh,

            directory=False,
            disabled=False
        )

        self._session_buttons = SessionButtonsF(
            parent=self._sc_scrollable.f_main_frame,

            start_eh=self._start_btn_eh,
            pause_eh=self._pause_btn_eh,
            stop_eh=self._stop_btn_eh,
            cancel_eh=self._cancel_btn_eh,

            disabled=True
        )

        self._train_sess_browse.config(
            pady=const.ETS_FRAME_PADY * 4,
        )

        self._session_buttons.config(
            pady=const.ETS_FRAME_PADY * 4,
        )

        # TODO

        """
        self._number_of_epochs_input.config(
            pady=30,
        )

        self._data_set_browse.config(
            pady=30,
        )
        """

    def _place_widgets(self):

        self._train_sess_browse.pack(side='top',
                                     fill='both',
                                     expand=True)

        self._train_sess_details_output.pack(side='top',
                                             fill='both',
                                             expand=True)

        # TODO

        """
        self._data_set_browse.pack(side='top',
                                   fill='both',
                                   expand=True)

        self._number_of_epochs_input.pack(side='top',
                                          fill='both',
                                          expand=True)
        """

        self._session_buttons.pack(side='top',
                                   fill='both',
                                   expand=True)

    #########################################################################
    # Event handling

    # ~~~~~~~~~~~~~~~~~~~~~Train session browse~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _train_session_selected_eh(
            self,

            selected_path):

        self._train_session_selected = True

        print('_train_session_selected_eh' + str(selected_path))

        # self._check_form_validity()   TODO

        self._alpha_version_check_form_validity()

        self._session_details = SessionController.read_main_session_file(
            session_file_path=selected_path
        )

        self._data_set_details = DataSetController.read_main_data_set_file(
            file_path=self._session_details.main_data_set_file
        )

        self._train_sess_details_output.update_session_details(
            data_set_details=self._data_set_details,
            session_details=self._session_details
        )

    # ~~~~~~~~~~~~~~~~~~~~~Data set browse~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _data_set_selected_eh(
            self,

            selected_path):

        self._valid_data_set_selected = True

        print('_data_set_selected_eh' + str(selected_path))

        # self._check_form_validity()   TODO

        self._alpha_version_check_form_validity()

    # ~~~~~~~~~~~~~~~~~~~~~Number of epochs~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _number_of_epochs_selected_eh(
            self,

            number_of_epochs):

        self._number_of_epochs_selected = True

        print('_number_of_epochs_selected_eh' + str(number_of_epochs))

        # self._check_form_validity()   TODO

        self._alpha_version_check_form_validity()

    # ~~~~~~~~~~~~~~~~~~~~~Session buttons~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _start_btn_eh(self):

        if self._first_start:
            self._first_start = False

            self._train_sess_details_output.destroy()
            # self._number_of_epochs_input.destroy()    TODO
            self._train_sess_browse.destroy()
            self._session_buttons.destroy()
            # self._data_set_browse.destroy()   TODO

            self._create_and_place_output_frame_and_canvas()

            self._session_buttons = SessionButtonsF(
                parent=self._sc_scrollable.f_main_frame,

                start_eh=self._start_btn_eh,
                pause_eh=self._pause_btn_eh,
                stop_eh=self._stop_btn_eh,
                cancel_eh=self._cancel_btn_eh,

                disabled=True
            )

            self._session_buttons.task_started()

            self._train_session_output = TrainSessOutputF(
                parent=self._sc_scrollable.f_main_frame,
            )

            self._session_buttons.pack(side='top',
                                       fill='both',
                                       expand=True)

            self._train_session_output.pack(side='top',
                                            fill='both',
                                            expand=True)

            self._train_session = TrainSession(
                add_message_method=self._train_session_output.new_message,
                training_finished=self.training_ended,
                data_set_details=self._data_set_details,
                session_details=self._session_details
            )

            CallMethodInNewThread.call_method(
                function_to_call=self._train_session.start_training
            )
        else:
            if self._train_session is not None:
                self._train_session.start_training()

        self._disable_train_sess_buttons()

    def _pause_btn_eh(self):

        if self._train_session is not None:
            self._train_session.pause_training()

    def _stop_btn_eh(self):

        if self._train_session is not None:
            self._train_session.stop_training()

    def _cancel_btn_eh(self):

        if self._train_session is not None:
            self._train_session.cancel_training()

    #########################################################################
    # Auxiliary methods

    def _validate_data_set_selection(
            self,

            selected_path):

        self._test_data_set_path = selected_path

        data_set_details = DataSetController.read_main_data_set_file(
            file_path=selected_path
        )

        return DataSetValidator.data_set_and_session_are_compatible(
            session_details=self._session_details,
            data_set_details=data_set_details
        )

    def _alpha_version_check_form_validity(self):

        if self._train_session_selected:
            self._train_sess_details_output.enable()
            self._session_buttons.enable()
        else:
            self._session_buttons.disable()
            self._train_sess_details_output.disable()

    def _check_form_validity(self):

        if self._train_session_selected:
            self._train_sess_details_output.enable()
            self._data_set_browse.enable()

            if self._valid_data_set_selected:
                self._number_of_epochs_input.enable()

                if self._number_of_epochs_selected:
                    self._session_buttons.enable()
                else:
                    self._session_buttons.disable()
            else:
                self._number_of_epochs_input.disable()
        else:
            self._train_sess_details_output.disable()
            self._number_of_epochs_input.disable()
            self._data_set_browse.disable()
            self._session_buttons.disable()

    #########################################################################
    # Public methods

    def training_ended(self):

        messagebox.showinfo(
            title='Training completed',
            message='Training completed.'
        )

        self._enable_train_sess_buttons()
    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,

            text=const.TSDI_INSTRUCTION,
            font=const.TSDI_FONT,
            justify='left'
        )

        self._f_browse = BrowseF(
            parent=self,

            initial_path=const.TSDI_BF_INITIAL_DIRECTORY,
            no_selection_message=const.TSDI_BF_NO_SELECTION,
            user_instruction=const.TSDI_BF_USER_INSTRUCTION,
            browse_window_title=const.TSDI_BF_WINDOW_TITLE,

            browse_button_eh=self._data_set_selected_eh,

            supported_files=const.TSDI_FILE_EXTENSION,

            directory=False,
            disabled=False
        )

        # TODO

        """
        from graphics.output.data_set.data_set_save_details_output_f import DataSetSaveDetailsOutputF

        self._selected_data_set_details = DataSetSaveDetailsOutputF(
            ...........
        )
        """

        self._cbi_nn_model = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_NN_MODEL_INSTRUCTION,
            user_options=const.TSDI_NN_MODEL_OPTIONS,

            selection_eh=self._neural_network_selected_eh,

            disabled=False
        )

        self._cbi_batch_size = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_BATCH_SIZE_INSTRUCTION,
            user_options=const.TSDI_BATCH_SIZE_OPTIONS,

            selection_eh=self._examples_per_batch_eh,

            disabled=False
        )

        self._cbi_epochs_nbr = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_EPOCHS_NBR_INSTRUCTION,
            user_options=const.TSDI_EPOCHS_NBR_OPTIONS,

            selection_eh=self._number_of_epochs_eh,

            disabled=False
        )

        self._cbi_image_size = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_IMAGE_SIZE_INSTRUCTION,
            user_options=const.TSDI_IMAGE_SIZE_OPTIONS,

            selection_eh=self._image_size_eh,

            disabled=False
        )

        if self._k_fold_cv_session:
            self._cbi_number_of_folds = ComboboxInputF(
                parent=self,

                user_instruction=const.TSDI_K_FOLD_CV_INSTRUCTION,
                user_options=const.TSDI_K_FOLD_CV_OPTIONS,

                selection_eh=self._number_of_folds_eh,

                disabled=False
            )
class TrainSessDetailsInputF(tk.Frame):
    """
    - Use to get user input regarding the details of a new training session.
    """

    def __init__(self,

                 parent,

                 valid_input_eh,
                 invalid_input_eh,

                 disabled=False,
                 k_fold_cv_session=False):
        """
        :param parent: Parent.

        :param valid_input_eh: Method that will be called when the form is 
                               completed. 
        :param invalid_input_eh: Method that will be called when the form is 
                                 not completed after the user made a change.

        :param disabled:    - Default: False;
                            - If True all the widgets will be disabled.

        :param k_fold_cv_session:   - Default: False;
                                    - True if this is used for a K-fold 
                                    cross-validation session.
        """

        tk.Frame.__init__(self,
                          parent,
                          padx=const.TSDI_FRAME_PADX,
                          pady=const.TSDI_FRAME_PADY)

        self._invalid_input_eh = invalid_input_eh
        self._valid_input_eh = valid_input_eh

        self._k_fold_cv_session = k_fold_cv_session

        self._create_widgets()
        self._place_widgets()

        self._sess_details = SessionDetails(
            k_fold_cv_session=k_fold_cv_session
        )

        if disabled:
            self.disable()

    #########################################################################
    # Widget creation and placement

    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,

            text=const.TSDI_INSTRUCTION,
            font=const.TSDI_FONT,
            justify='left'
        )

        self._f_browse = BrowseF(
            parent=self,

            initial_path=const.TSDI_BF_INITIAL_DIRECTORY,
            no_selection_message=const.TSDI_BF_NO_SELECTION,
            user_instruction=const.TSDI_BF_USER_INSTRUCTION,
            browse_window_title=const.TSDI_BF_WINDOW_TITLE,

            browse_button_eh=self._data_set_selected_eh,

            supported_files=const.TSDI_FILE_EXTENSION,

            directory=False,
            disabled=False
        )

        # TODO

        """
        from graphics.output.data_set.data_set_save_details_output_f import DataSetSaveDetailsOutputF

        self._selected_data_set_details = DataSetSaveDetailsOutputF(
            ...........
        )
        """

        self._cbi_nn_model = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_NN_MODEL_INSTRUCTION,
            user_options=const.TSDI_NN_MODEL_OPTIONS,

            selection_eh=self._neural_network_selected_eh,

            disabled=False
        )

        self._cbi_batch_size = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_BATCH_SIZE_INSTRUCTION,
            user_options=const.TSDI_BATCH_SIZE_OPTIONS,

            selection_eh=self._examples_per_batch_eh,

            disabled=False
        )

        self._cbi_epochs_nbr = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_EPOCHS_NBR_INSTRUCTION,
            user_options=const.TSDI_EPOCHS_NBR_OPTIONS,

            selection_eh=self._number_of_epochs_eh,

            disabled=False
        )

        self._cbi_image_size = ComboboxInputF(
            parent=self,

            user_instruction=const.TSDI_IMAGE_SIZE_INSTRUCTION,
            user_options=const.TSDI_IMAGE_SIZE_OPTIONS,

            selection_eh=self._image_size_eh,

            disabled=False
        )

        if self._k_fold_cv_session:
            self._cbi_number_of_folds = ComboboxInputF(
                parent=self,

                user_instruction=const.TSDI_K_FOLD_CV_INSTRUCTION,
                user_options=const.TSDI_K_FOLD_CV_OPTIONS,

                selection_eh=self._number_of_folds_eh,

                disabled=False
            )

    def _place_widgets(self):

        self._lbl_title.pack(side='top',
                             fill='both',
                             expand=True)

        self._f_browse.pack(side='top',
                            fill='both',
                            expand=True)

        self._cbi_nn_model.pack(side='top',
                                fill='both',
                                expand=True)
        self._cbi_batch_size.pack(side='top',
                                  fill='both',
                                  expand=True)
        self._cbi_epochs_nbr.pack(side='top',
                                  fill='both',
                                  expand=True)
        self._cbi_image_size.pack(side='top',
                                  fill='both',
                                  expand=True)

        if self._k_fold_cv_session:
            self._cbi_number_of_folds.pack(side='top',
                                           fill='both',
                                           expand=True)

    #########################################################################
    # Event handling

    def _data_set_selected_eh(
            self,

            data_set_path: str):
        """ Called when the user selects a data set."""

        self._sess_details.main_data_set_file = data_set_path

        self._check_form_completion()

    def _neural_network_selected_eh(
            self,

            neural_network):
        """ 
        - Called when the user selects a neural network model.
        """

        self._sess_details.neural_network = neural_network

        self._check_form_completion()

    def _examples_per_batch_eh(
            self,

            example_per_batch):
        """ 
        - Called when the user selects the number of examples per batch.
        """

        self._sess_details.examples_per_batch = int(example_per_batch)

        self._check_form_completion()

    def _number_of_epochs_eh(
            self,

            number_of_epochs):
        """ 
        - Called when the user selects the number of epochs.
        """

        self._sess_details.number_of_epochs = int(number_of_epochs)

        self._check_form_completion()

    def _image_size_eh(
            self,

            img_size):
        """ 
        - Called when the user selects the image size.
        """

        self._sess_details.image_size = int(img_size)

        self._check_form_completion()

    def _number_of_folds_eh(
            self,

            number_of_folds):
        """ 
        - Called when the user selects the image size.
        """

        self._sess_details.number_of_folds = int(number_of_folds)

        self._check_form_completion()

    def _check_form_completion(self):
        """
        - Checks if the input form is completed

        :return: - True if the form is completed
                 - False otherwise
        """

        if self._sess_details.session_details_input_are_valid():
            self._valid_input_eh()
        else:
            self._invalid_input_eh()

    #########################################################################
    # Public methods

    def get_input(self):

        return self._sess_details

    def enable(self):
        """ Enables all the widgets."""

        if self._k_fold_cv_session:
            self._cbi_number_of_folds.enable()

        self._lbl_title.config(state='normal')
        self._cbi_batch_size.enable()
        self._cbi_epochs_nbr.enable()
        self._cbi_image_size.enable()
        self._cbi_nn_model.enable()
        self._f_browse.enable()

    def disable(self):
        """ Disables all the widgets."""

        if self._k_fold_cv_session:
            self._cbi_number_of_folds.disable()

        self._lbl_title.config(state='disabled')
        self._cbi_batch_size.disable()
        self._cbi_epochs_nbr.disable()
        self._cbi_image_size.disable()
        self._cbi_nn_model.disable()
        self._f_browse.disable()
Exemple #8
0
class NewKFoldCVSessGUI(tk.Frame):
    def __init__(self, parent, enable_k_fold_cv_sess_buttons,
                 disable_k_fold_cv_sess_buttons):
        """
        :param parent: 
        :param enable_k_fold_cv_sess_buttons: 
        :param disable_k_fold_cv_sess_buttons: 
        """

        tk.Frame.__init__(self, parent)

        self._disable_k_fold_cv_sess_buttons = disable_k_fold_cv_sess_buttons
        self._enable_k_fold_cv_sess_buttons = enable_k_fold_cv_sess_buttons

        self._valid_train_session_details_input = False
        self._valid_train_sess_save_details = False

        self._sc_scrollable = None
        self._f_output = None

        self._display_options = []

        self._first_start = True

        self._create_widgets()
        self._place_widgets()

    #########################################################################
    # Widget creation and placement

    def _create_and_place_output_frame_and_canvas(self):

        if self._sc_scrollable:
            self._sc_scrollable.destroy()
            del self._sc_scrollable

        if self._f_output:
            self._f_output.destroy()
            del self._f_output

        self._f_output = tk.Frame(self, )

        self._sc_scrollable = ScrollableCanvasC(parent=self._f_output, )

        self._sc_scrollable.pack(side='top', fill='both', expand=True)

        self._f_output.pack(side='top', fill='both', expand=True)

    def _create_widgets(self):

        self._create_and_place_output_frame_and_canvas()

        self._data_augmentation = DataAugmentationInputF(
            parent=self._sc_scrollable.f_main_frame,
            selection_eh=self._data_augmentation_selection_eh,
            disabled=True)

        self._train_session_details_input = TrainSessDetailsInputF(
            parent=self._sc_scrollable.f_main_frame,
            valid_input_eh=self._valid_session_details_eh,
            invalid_input_eh=self._invalid_session_details_eh,
            k_fold_cv_session=True,
            disabled=True)

        self._train_sess_save_details = FileSaveDetailsInputF(
            parent=self._sc_scrollable.f_main_frame,
            file_extension=const.NTSG_EXTENSION,
            valid_input_eh=self._valid_save_details_eh,
            invalid_input_eh=self._invalid_save_details_eh,
            disabled=False)

        self._session_buttons = SessionButtonsF(
            parent=self._sc_scrollable.f_main_frame,
            start_eh=self._start_btn_eh,
            pause_eh=self._pause_btn_eh,
            stop_eh=self._stop_btn_eh,
            cancel_eh=self._cancel_btn_eh,
            disabled=False)

    def _place_widgets(self):

        self._sc_scrollable.pack(side='top', fill='both', expand=True)

        self._train_sess_save_details.pack(side='top',
                                           fill='both',
                                           expand=True)

        self._train_session_details_input.pack(side='top',
                                               fill='both',
                                               expand=True)

        self._data_augmentation.pack(side='top', fill='both', expand=True)

        self._session_buttons.pack(side='top', fill='both', expand=True)

    #########################################################################
    # Event handling

    # ~~~~~~~~~~~~~~~~~~~~~Data augmentation~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _data_augmentation_selection_eh(self):

        # TODO

        pass

    # ~~~~~~~~~~~~~~~~~~~~~Data augmentation~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _fold_number_selected_eh(self, selected_value):

        # TODO

        if selected_value != 'Overall':
            self._train_session_output.pack_forget()
            self._test_sess_output.pack_forget()

            self._train_session_output.pack(side='top',
                                            fill='both',
                                            expand=True)
            self._test_sess_output.pack(side='top', fill='both', expand=True)
        else:
            self._train_session_output.pack_forget()

        print('_fold_number_selected_eh    ' + selected_value)

    # ~~~~~~~~~~~~~~~~~~~~~Save details~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _valid_save_details_eh(self, save_details):

        self._valid_train_sess_save_details = True

        print('_valid_save_details_eh    ' + str(save_details))

        self._check_form_validity()

    def _invalid_save_details_eh(self):

        self._valid_train_sess_save_details = False

        print('_invalid_save_details_eh')

        self._check_form_validity()

    # ~~~~~~~~~~~~~~~~~~~~~Session details~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _valid_session_details_eh(self):

        session_details = self._train_session_details_input.get_input()
        self._valid_train_session_details_input = True
        self._display_options = ["Overall"]

        for i in range(int(session_details.number_of_folds)):
            self._display_options.append(str(i + 1))

        print('_valid_session_details_eh')

        self._check_form_validity()

    def _invalid_session_details_eh(self):

        self._valid_train_session_details_input = False

        print('_invalid_session_details_eh')

        self._check_form_validity()

    # ~~~~~~~~~~~~~~~~~~~~~Session buttons~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def _start_btn_eh(self):

        if self._first_start:
            self._first_start = False

            self._train_session_details_input.destroy()
            self._train_sess_save_details.destroy()
            self._data_augmentation.destroy()

            self._create_and_place_output_frame_and_canvas()

            self._fold_number_input = ComboboxInputF(
                parent=self._sc_scrollable.f_main_frame,
                user_instruction=const.KFCVESG_K_TEXT,
                user_options=self._display_options,
                selection_eh=self._fold_number_selected_eh,
            )

            self._fold_number_input.config(pady=30)

            self._train_session_output = TrainSessOutputF(
                parent=self._sc_scrollable.f_main_frame, )

            self._test_sess_output = TestSessOutputF(
                parent=self._sc_scrollable.f_main_frame)

            self._test_sess_output.progress_bar.pack_forget()

            self._fold_number_input.pack(side='top', fill='both', expand=True)

            self._train_session_output.pack(side='top',
                                            fill='both',
                                            expand=True)

            self._test_sess_output.pack(side='top', fill='both', expand=True)

            # TODO -> Call the controller to start the training session.

            from utils.call_method_in_new_thread import CallMethodInNewThread

            CallMethodInNewThread.call_method(
                function_to_call=self.mock_data_set_creation, )

    def _pause_btn_eh(self):

        # TODO

        print(str(self._train_session_details_input.get_input()))
        print(str(self._train_sess_save_details.get_new_file_details()))
        print(str(self._data_augmentation.get_input()))

    def _stop_btn_eh(self):

        # TODO

        pass

    def _cancel_btn_eh(self):

        # TODO

        pass

    #########################################################################
    # Auxiliary methods

    def _check_form_validity(self):

        if self._valid_train_sess_save_details:
            self._train_session_details_input.enable()
            self._data_augmentation.enable()

            if self._valid_train_session_details_input:
                self._session_buttons.enable()
            else:
                self._session_buttons.disable()
                self._data_augmentation.disable()
        else:
            self._train_session_details_input.disable()
            self._data_augmentation.disable()
            self._session_buttons.disable()

    #########################################################################
    # Public methods

    #########################################################################
    # Temporary methods

    def mock_data_set_creation(self):

        from random import random
        from time import sleep

        for i in range(25):

            message = TrainSessMessage()

            message.step = i
            message.loss = random() * 100
            message.seconds_per_batch = random() * 100
            message.examples_per_sec = random() * 100

            self._train_session_output.new_message(message=message)

            sleep(0.2)
Exemple #9
0
class TestSessChartsF(tk.Frame):
    """
    - Use to display charts with the results of the test session.
    """

    def __init__(self,

                 parent,

                 disabled=False):
        """
        :param parent: Parent.

        :param disabled:    - Default: False;
                            - If True all the widgets will be disabled.
        """

        tk.Frame.__init__(self,
                          parent,
                          relief=const.TESC_FRAME_RELIEF,
                          padx=const.TESC_FRAME_PADX,
                          pady=const.TESC_FRAME_PADY,
                          bd=const.TESC_FRAME_BD)

        self._test_sess_charts = TestSessCharts()

        self._create_widgets()
        self._place_widgets()

        if disabled:
            self.disable()

    #########################################################################
    # Widget handling

    def _create_widgets(self):

        self._lbl_title = tk.Label(
            self,

            font=const.TESC_TITLE_FONT,
            text=const.TESC_TITLE_TEXT,

            padx=const.TESC_TITLE_PADX,
            pady=const.TESC_TITLE_PADY,
        )

        self._f_output = tk.Frame(
            self,

            relief=const.TESC_SUBFRAME_RELIEF,
            padx=const.TESC_SUBFRAME_PADX,
            pady=const.TESC_SUBFRAME_PADY,
            bd=const.TESC_SUBFRAME_BD,
        )

        self._f_chart = tk.Frame(
            self._f_output,
        )

        self._ci_chart_to_display = ComboboxInputF(
            parent=self._f_output,

            user_instruction=const.TESC_CHARTS_TEXT,
            user_options=const.TESC_CHARTS_OPTIONS,

            selection_eh=self._chart_selected_eh,
        )

        self._column_chart = ColumnChart(
            parent=self._f_chart
        )

    def _place_widgets(self):

        self._lbl_title.pack(side='top',
                             fill='both',
                             expand=True)

        self._ci_chart_to_display.pack(side='top',
                                       fill='both',
                                       expand=True)

        self._column_chart.pack(side='top')

        self._f_chart.place(in_=self._column_chart,
                            anchor="c",
                            relx=.5,
                            rely=.5)

        self._f_chart.pack(side='top',
                           fill='both',
                           expand=True)

        self._f_output.pack(side='top',
                            fill='both',
                            expand=True)

    #########################################################################
    # Event handling

    def _chart_selected_eh(
            self,

            selected_text: str):
        """
        - Called when the user selects a chart name.
        
        :param selected_text: selected text. 
        """

        chart = self._test_sess_charts.get_chart(selected_text)

        if chart is not None:
            self._column_chart.update_values(chart_entries=chart)

    #########################################################################
    # Public methods

    def update_chart_values(
            self,

            test_sess_charts: TestSessCharts):
        """
        - Updates the charts details.
        
        :param test_sess_charts: Details about the charts, it must be a 
                                 valid instance of TestSessCharts or it will
                                 raise ValueError.
        """

        if isinstance(test_sess_charts, TestSessCharts) \
                and test_sess_charts.is_valid():
            self._test_sess_charts = test_sess_charts
        else:
            raise ValueError('test_sess_charts is not a valid instance of '
                             'TestSessCharts')

    def enable(self):
        """ Enables all the widgets."""

        self._lbl_title.config(state='normal')
        self._ci_chart_to_display.enable()

    def disable(self):
        """ Disables all the widgets."""

        self._ci_chart_to_display.disable()
        self._lbl_title.config(state='disabled')