def __init__(self, key, file_path): """ :param key: key to write data to :param file_path: file path to write/update data to """ self.key = key self.file_path = file_path self.udata = None self.json_reader = JSONReader(self.key, self.file_path)
def __init__(self, data_name: str): self.metadata_reader = JSONReader(data_name, dataset_metafile_path) self.metadata_reader.bulk_read() self.metadata_reader.select() image_metadata = self.metadata_reader.selected_data self.n_columns = image_metadata["n_columns"] self.training_data_path = image_metadata["data_path"] self.n_classes = image_metadata["n_classes"] self.dataset_type = image_metadata["dataset_type"] if not self.dataset_type == 'training': raise AssertionError() self.data_len = image_metadata["data_len"] self.width = image_metadata["width"] self.height = image_metadata["height"] self.dataset_name = image_metadata["dataset_name"]
def __init__(self, training_name: str): self.training_name = training_name self.training_metadata_reader = JSONReader(self.training_name, training_metafile_path) self.training_metadata_reader.bulk_read() self.training_metadata_reader.select() training_metadata = self.training_metadata_reader.selected_data self.model_name = training_metadata["model_name"] self.training_dataset_name = training_metadata["dataset_name"] self.n_classes = training_metadata["n_classes"] self.architecture = training_metadata["architecture"] self.height = training_metadata["height"] self.width = training_metadata["width"] self.n_channels = training_metadata["n_channels"]
def __init__(self, data_name: str): self.data_name = data_name self.metadata_reader = JSONReader(self.data_name, dataset_metafile_path) self.metadata_reader.bulk_read() self.metadata_reader.select() image_metadata = self.metadata_reader.selected_data self.data_path = image_metadata["data_path"] self.width = image_metadata["width"] self.height = image_metadata["height"] self.path_file = image_metadata["path_file"] self.trainable = image_metadata["trainable"] if ast.literal_eval(self.trainable): raise AssertionError("Data is trainable")
class JSONWriter: def __init__(self, key, file_path): """ :param key: key to write data to :param file_path: file path to write/update data to """ self.key = key self.file_path = file_path self.udata = None self.json_reader = JSONReader(self.key, self.file_path) def parse(self): keys = [key for key in self.udata] values = [val for val in self.udata.values()] return keys, values def read(self): self.json_reader.bulk_read() return self.json_reader.bulk_data def update(self, **udata): """ :param udata: **kwargs data to write in JSON file """ self.udata = udata keys, values = self.parse() fdata = self.read() try: for key, val in zip(keys, values): fdata[self.key][key] = val except KeyError: fdata[self.key] = {} for key, val in zip(keys, values): fdata[self.key][key] = val self.udata = fdata def write(self): with open(self.file_path, 'w') as jsonfile: json.dump(self.udata, jsonfile, indent=3)