cur_shape_iou_tot += I/U cur_shape_iou_cnt += 1. if cur_shape_iou_cnt > 0: cur_shape_miou = cur_shape_iou_tot / cur_shape_iou_cnt shape_iou_tot += cur_shape_miou shape_iou_cnt += 1. shape_mIoU = shape_iou_tot / shape_iou_cnt part_iou = np.divide(part_intersect[1:], part_union[1:]) mean_part_iou = np.mean(part_iou) opt.printer.info("===> Category {}-{}, Part mIOU is{:.4f} \t ".format( opt.category_no, opt.category, mean_part_iou)) if __name__ == '__main__': opt = OptInit().initialize() opt.printer.info('===> Creating dataloader ...') test_dataset = PartNet(opt.data_dir, opt.dataset, opt.category, opt.level, 'val') test_loader = DenseDataLoader(test_dataset, batch_size=1, shuffle=True, num_workers=1) opt.n_classes = test_loader.dataset.num_classes opt.printer.info('===> Loading the network ...') model = DenseDeepGCN(opt).to(opt.device) opt.printer.info('===> loading pre-trained ...') model, opt.best_value, opt.epoch = load_pretrained_models(model, opt.pretrained_model, opt.phase) test(model, test_loader, opt)
state = { 'epoch': opt.epoch, 'state_dict': model_cpu, 'optimizer_state_dict': optimizer.state_dict(), 'scheduler_state_dict': scheduler.state_dict(), 'best_value': opt.best_value, } torch.save(state, filename) logging.info('save a new best model into {}'.format(filename)) if __name__ == '__main__': opt = OptInit()._get_args() logging.info('===> Creating dataloader ...') train_dataset = PartNet(opt.data_dir, 'sem_seg_h5', opt.category, opt.level, 'train') train_loader = DenseDataLoader(train_dataset, batch_size=opt.batch_size, shuffle=True, num_workers=8) test_dataset = PartNet(opt.data_dir, 'sem_seg_h5', opt.category, opt.level, 'test') test_loader = DenseDataLoader(test_dataset, batch_size=opt.test_batch_size, shuffle=False, num_workers=8) val_dataset = PartNet(opt.data_dir, 'sem_seg_h5', opt.category, opt.level, 'val') val_loader = DenseDataLoader(val_dataset, batch_size=opt.test_batch_size, shuffle=False, num_workers=8) opt.n_classes = train_dataset.num_classes logging.info('===> Loading PartNet Category {}-{}, Semantic Segmentation level {}. ' 'Has classes {}'.format(opt.category_no, opt.category, opt.level, opt.n_classes)) logging.info('===> Loading the network ...') model = DeepGCN(opt).to(opt.device) if opt.multi_gpus:
cur_shape_miou = cur_shape_iou_tot / cur_shape_iou_cnt shape_iou_tot += cur_shape_miou shape_iou_cnt += 1. shape_mIoU = shape_iou_tot / shape_iou_cnt part_iou = np.divide(part_intersect[1:], part_union[1:]) mean_part_iou = np.mean(part_iou) opt.printer.info( "===> Category {}-{}, Part mIOU is{:.4f} \t Shape mIoU is{:.4f} ". format(opt.category_no, opt.category, mean_part_iou, shape_mIoU)) if __name__ == '__main__': opt = OptInit().initialize() opt.printer.info('===> Creating dataloader ...') test_dataset = PartNet(opt.train_path, opt.dataset, opt.category, opt.level, 'val') test_loader = DenseDataLoader(test_dataset, batch_size=1, shuffle=True, num_workers=1) opt.n_classes = test_loader.dataset.num_classes opt.printer.info('===> Loading the network ...') model = DenseDeepGCN(opt).to(opt.device) opt.printer.info('===> loading pre-trained ...') model, opt.best_value, opt.epoch = load_pretrained_models( model, opt.pretrained_model, opt.phase) test(model, test_loader, opt)
cur_shape_iou_tot += I/U cur_shape_iou_cnt += 1. if cur_shape_iou_cnt > 0: cur_shape_miou = cur_shape_iou_tot / cur_shape_iou_cnt shape_iou_tot += cur_shape_miou shape_iou_cnt += 1. shape_mIoU = shape_iou_tot / shape_iou_cnt part_iou = np.divide(part_intersect[1:], part_union[1:]) mean_part_iou = np.mean(part_iou) logging.info("===> Finish Testing! Category {}-{}, Part mIOU is {:.4f} \n\n\n ".format( opt.category_no, opt.category, mean_part_iou)) if __name__ == '__main__': opt = OptInit()._get_args() logging.info('===> Creating dataloader ...') test_dataset = PartNet(opt.data_dir, 'sem_seg_h5', opt.category, opt.level, 'test') test_loader = DenseDataLoader(test_dataset, batch_size=1, shuffle=True, num_workers=1) opt.n_classes = test_loader.dataset.num_classes logging.info('===> Loading the network ...') model = DeepGCN(opt).to(opt.device) logging.info('===> loading pre-trained ...') model, opt.best_value, opt.epoch = load_pretrained_models(model, opt.pretrained_model, opt.phase) test(model, test_loader, opt)