def __init__(self, image_size=224, num_classes=200): self.image_size = image_size self.net = ClassNet(num_classes=num_classes).cuda() self.transform_train, self.transform_test = MyTransform.transform_train_cam( image_size=self.image_size) self.transform_un_normalize = MyTransform.transform_un_normalize() pass
def __init__(self, image_size=224, num_classes=200): self.image_size = image_size self.net = CAMNet(num_classes=num_classes).cuda() self.name_to_label_id, self.label_info_dict = DataUtil.get_class_name() self.transform_train, self.transform_test = MyTransform.transform_train_cam( image_size=self.image_size) self.transform_un_normalize = MyTransform.transform_un_normalize() pass
def eval_ss(self, data_loader, epoch=0, model_file_name=None, save_path=None): if model_file_name is not None: Tools.print("Load model form {}".format(model_file_name), txt_path=self.config.ss_save_result_txt) self.load_model(model_file_name) pass un_norm = MyTransform.transform_un_normalize() self.net.eval() metrics = StreamSegMetrics(self.config.ss_num_classes) with torch.no_grad(): for i, (inputs, labels, _) in tqdm(enumerate(data_loader), total=len(data_loader)): inputs = inputs.float().cuda() labels = labels.long().cuda() outputs = self.net(inputs) preds = outputs.detach().max(dim=1)[1].cpu().numpy() targets = labels.cpu().numpy() metrics.update(targets, preds) if save_path: for j, (input_one, label_one, pred_one) in enumerate(zip(inputs, targets, preds)): un_norm(input_one.cpu()).save(os.path.join(save_path, "{}_{}.JPEG".format(i, j))) DataUtil.gray_to_color(np.asarray(label_one, dtype=np.uint8)).save( os.path.join(save_path, "{}_{}_l.png".format(i, j))) DataUtil.gray_to_color(np.asarray(pred_one, dtype=np.uint8)).save( os.path.join(save_path, "{}_{}_p.png".format(i, j))) pass pass pass pass score = metrics.get_results() Tools.print("{} {}".format(epoch, metrics.to_str(score)), txt_path=self.config.ss_save_result_txt) return score
def __init__(self, image_size=256, num_classes=200): self.image_size = image_size self.num_classes = num_classes self.net = ClassNet(num_classes=self.num_classes).cuda() self.name_to_label_id, self.label_info_dict = DataUtil.get_class_name(data_root=self.get_data_root_path()) self.transform_train, self.transform_test = MyTransform.transform_train_cam(image_size=self.image_size) pass
def __init__(self, config): self.config = config self.net = CAMNet(num_classes=self.config.mlc_num_classes).cuda() self.dataset_vis_cam = DatasetUtil.get_dataset_by_type( DatasetUtil.dataset_type_vis_cam, image_size=self.config.mlc_size, data_root=self.config.data_root_path, return_image_info=True, sampling=self.config.sampling) self.data_loader_vis_cam = DataLoader(self.dataset_vis_cam, self.config.mlc_batch_size, shuffle=False, num_workers=16) self.transform_un_normalize = MyTransform.transform_un_normalize() pass
def __init__(self, image_size=256, num_classes=2): self.net = ClassNet(num_classes=num_classes).cuda() self.transform_train, self.transform_test = MyTransform.transform_train_cam(image_size=image_size) # self.transform_test = MyTransform.transform_vis_cam(image_size=image_size) pass