def nii(input_folder, output_folder): """ Take a folder, recursively traverse through all its subfolders, convert each subfolder into a NII file :param input_folder: :param output_folder: :return: """ os.chdir(output_folder) create("nii") logger.info("Generating NII files:") path_nii = os.path.join(output_folder, "nii") DICOM_convert.to_nii(input_folder, path_nii) DICOM_convert.fix_series(path_nii) logger.info("Nii files generated!")
def raw_sorted(input_folder, output_folder): """ FLATCOPY (with timestampe to avoid naming duplications) to a an output folder with raw prefix, then SORT THEM with proper protocole series acquisition number. :param input_folder: :param output_folder: :return: """ os.chdir(output_folder) os.chdir(output_folder) create("raw_sorted") logger.info("Generating sorted raw files:") path_raw_sorted = os.path.join(output_folder, "raw_sorted") DICOM_sort.into_folder(input_folder, path_raw_sorted) DICOM_convert.fix_series(path_raw_sorted) logger.info("Sorted raw files completed!")
def DICOM_universal_convert_default( input_root_folder, name_default_folder=f"DICOM_UniversalConvert-{unique_name()}"): """ Create a new folder with :param input_root_folder: :return: """ logger.info("Begin converting folder: " + input_root_folder) # Generate the potential name for the new path. path_result = f"{input_root_folder}-{name_default_folder}" # intellgently create the folder if needed be. create(path_result) # Trigger the subject specific convertion. DICOM_converter.DICOM_universal_convert(input_root_folder, path_result) logger.info(f"Finished converting: {input_root_folder}")
def DICOMOBJ_converter( input_root_folder, default_folder=f"DICOM_UniversalConvert-{unique_name()}"): """ Create a new folder with :param input_root_folder: :return: """ path_list = DICOM_converter.DICOMOBJ_finder(input_root_folder) for path in path_list: logger.info("Begin converting folder: " + path) # Get higher folder path. path_source = os.path.dirname(path) # Generate the potential name for the new path. path_result = os.path.join(path_source, default_folder) # intellgently create the folder if needed be. create(path_result) # Trigger the subject specific convertion. DICOM_converter.DICOM_universal_convert(path, path_result) logger.info(f"Finished converting: {path}")
from imageio import imsave from pathlib import Path path_current_file = Path(os.path.realpath(__file__)) path_module = path_current_file.parents[ 2] # this file is located 3 folders deep: /, /model, /model/Kaggle_DCGAN_Dogs print(f"{path_module}") sys.path.append(f"{path_module}") # Some convenience function I already prebuilt: github.com/dyt811/PythonUtils/ from PythonUtils.PUFile import unique_name from PythonUtils.PUFolder import recursive_list, create path_log_run = path_module / Path("logs") / unique_name() create(path_log_run ) # create the training specific folder if it doesn't exist already. # dimensions_noise = 100 """ Largely inspired from source: https://github.com/DataSnaek/DCGAN-Keras """ class DCGAN: def __init__(self, path_discriminator, path_generator, path_output, img_size): # Key image properties. self.img_size = img_size # default x and y self.channels = 3
def __init__( self, input_shape, output_classes, train_data_path: Path, optimizer="adam", loss="mse", metrics=None, checkpoint_metric="val_loss", checkpoint_metric_mode="min", ): # Use these settings per constructor input. self.input_shape = input_shape self.output_classes = output_classes self.loss = loss self.optimizer = optimizer # Default metrics if metrics is None: self.metrics = ([ "mae", "mse", "mape", "cosine", loss_SSIM, loss_mae_diff_SSIM_composite, loss_mse_diff_SSIM_composite, f1_metric, ], ) else: self.metrics = metrics self.checkpoint_metric = checkpoint_metric self.checkpoint_metric_mode = checkpoint_metric_mode self.train_data = None self.path_train_data: Path = train_data_path self.test_data = None # fixme: independent data used for testing (optional?) self.callbacks_list = None self.model = None self.path_prediction = None # Default step and epoch size. Easily overwritten during the run stage. self.size_step = 256 self.size_epoch = 500 # Dynamically generate model input_path. this_file = os.path.realpath(__file__) project_root = get_abspath( this_file, 2 ) # todo: this folder path is hard coded. Needs to be generalized. # Log path. self.path_log, self.path_model = get_paths(project_root) # Log run path. self.path_log_run = os.path.join(self.path_log, unique_name() + __name__) # Create the Log run path. create(self.path_log_run) self.model_stage = stage.Initialized