def compute_on_dir(self, dirpath, outdir): """ Computes the output of all images in a directory with 'im' in their name. Args: dirpath (string): path to the data folder outdir (string): path to the output folder. Created if not existing. Returns: """ if not os.path.isdir(outdir): os.mkdir(outdir) _, _, files = next(os.walk(dirpath)) dir_len = 0 for file in files: if 'im' in file: dir_len += 1 gen = BatchGenerator(traindir=dirpath, city_model=self, trainsetsize=dir_len, batchsize=1, traindirsize=dir_len) counter = 0 inputs = gen.generate_input_only(option=self.prop_dict['trainset'][0]) for x in inputs: if counter > dir_len: break x = np.squeeze(x,axis=0) y = np.squeeze(self.compute_output(x),axis=0) Im = Image.fromarray(x[:,:,0:3].astype('uint8')) Out = Image.fromarray(y.astype('uint8')) Im.save(os.path.join(outdir,'input_'+str(counter)+'_.png')) Out.save((os.path.join(outdir,'output_'+str(counter)+'_.png'))) counter += 1 print(str(counter))
def evaluate_full(self, validation_dir, validation_option = '', logfile=None): valdirsize = len([name for name in os.listdir(validation_dir) if os.path.isfile(os.path.join(validation_dir,name)) and 'im' in name]) val_gen = BatchGenerator(traindir=validation_dir, city_model=self, trainsetsize=valdirsize, batchsize=1, traindirsize=valdirsize) counter = 0 gen = val_gen.generate_input_only(validation_option) metrics = ['acc'] for met in Metrics.valid_metrics: metrics.append(Metrics.create_metrics(met,self))