def is_valid(self): """ - Checks if valid :return: - True if valid - False otherwise """ if not isinstance(self.directory_path, str) \ or not isinstance(self.description, str) \ or not isinstance(self.file_name, str): return False if self.directory_path == '' \ or self.description == '' \ or self.file_name == '': return False file_path = self.directory_path + '/' + self.file_name if not fe.is_directory(self.directory_path) \ or not fe.is_file(file_path): return False return True
def _directory_path_changed_eh(self, directory_path: str): """ Automatically called when the directory is changed. :param directory_path: Path of the new directory. """ self._f_name_input.change_directory_path(directory_path) if isinstance(directory_path, str) \ and directory_path != '' \ and fe.is_directory(directory_path): self._file_input.directory_path = directory_path self._f_name_input.enable() # If the user completed the form but at some point the directory # was no longer valid but now it is. This will trigger the file # name change event handler. if self._file_input.file_name != '': self._file_name_changed_eh(self._file_input.file_name) else: self._file_input.directory_path = '' self._f_name_input.disable() self._description.disable() self._invalid_input_eh()
def is_valid(self): """ - Checks if valid :return: - True if valid - False otherwise """ if self.cifar10 and not self.imagenet and not self.images \ or not self.cifar10 and self.imagenet and not self.images \ or not self.cifar10 and not self.imagenet and self.images: if self.cifar10: if not self.cifar10_train_ds and not self.cifar10_test_ds: return False if self.images: if not fe.is_directory(self.data_set_location): return False if not self.class_correlation.is_valid(): return False return True else: return False
def data_set_location(self, value: str): if self._images and not fe.is_directory(value) \ or not isinstance(value, str): raise ValueError('Data set location must be a string and also a ' 'valid path.') self._data_set_location = value
def _from_images_eh(self): """ - Called when the user wants to use folders with images as initial data set. """ self._data_set_details.data_set_location = filedialog.askdirectory( title=const.IDSP_FROM_IMAGES_INITIAL_DIR, initialdir=const.IDSP_FROM_IMAGES_TITLE) selected_path = self._data_set_details.data_set_location # Checks if the user has selected a directory. if isinstance(selected_path, str) and selected_path != '': # Checks if the received path is a directory. if f_expert.is_directory(selected_path): # Gets a list with all the visible subdirectories. self._data_set_details.identifiers = \ f_expert.get_directories(selected_path) # Updates the identifier list self._cii_class_input.update_data_set_identifier( self._data_set_details.identifiers) # Sets teh previous selection value to the current button. self._previous_selection = const.IDSP_FROM_IMAGES_VAL # Saving details about the initial data set. self._data_set_details.cifar10 = False self._data_set_details.imagenet = False self._data_set_details.images = True # Until the user selects the identifiers for each class the # form is invalid. self._invalid_cii_form_eh() self._lbl_instruction.forget() else: # If the user did not select a directory. if self._previous_selection != const.IDSP_NO_SELECTION_VAL: # If another initial data set was selected before, that # button is selected again. self._qna_initial_data_set.select_button( self._previous_selection) else: # If no initial data set was selected before, the current # button is deselected. self._qna_initial_data_set.deselect_button( const.IDSP_FROM_IMAGES_VAL)
def _make_sure_the_required_files_exist(self): """ - Makes sure that the Cifar10 files exist and are valid. """ if not fe.is_directory(const.CIFAR10_SAVE_LOCATION): fe.crete_directory(const.CIFAR10_SAVE_LOCATION) if self._download_cifar10(): self._extract_cifar10() else: if DataSetValidator.check_if_extract_is_needed(): if DataSetValidator.check_if_download_is_needed(): if not self._download_cifar10(): return self._extract_cifar10()
def check_if_extract_is_needed(): """ :return: - True if the extract is required. - False otherwise. """ cifar10_directory_exists = fe.is_directory( path=const.CIFAR10_DIRECTORY_PATH ) if not cifar10_directory_exists \ or not DataSetValidator.cifar10_files_exist_and_are_valid() \ and cifar10_directory_exists: return True return False