()
Create the model and start the evaluation process.
Create the model and start the evaluation process.
Create the model and start the evaluation process .
def main():
    """Create the model and start the evaluation process."""
    args = get_arguments()

    os.environ["CUDA_VISIBLE_DEVICES"]=args.gpu
    gpus = [int(i) for i in args.gpu.split(',')]

    h, w = map(int, args.input_size.split(','))
    
    input_size = (h, w)

    model = Res_Deeplab(num_classes=args.num_classes)

    normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225])

    transform = transforms.Compose([
        transforms.ToTensor(),
        normalize,
    ])

    lip_dataset = LIPDataSet(args.data_dir, 'val', crop_size=input_size, transform=transform)
    num_samples = len(lip_dataset)

    valloader = data.DataLoader(lip_dataset, batch_size=args.batch_size * len(gpus),
                                shuffle=False, pin_memory=True)

    restore_from = args.restore_from

    state_dict = model.state_dict().copy()
    state_dict_old = torch.load(restore_from)

    for key, nkey in zip(state_dict_old.keys(), state_dict.keys()):
        if key != nkey:
            # remove the 'module.' in the 'key'
            state_dict[key[7:]] = deepcopy(state_dict_old[key])
        else:
            state_dict[key] = deepcopy(state_dict_old[key])

    model.load_state_dict(state_dict)

    model.eval()
    model.cuda()

    parsing_preds, scales, centers = valid(model, valloader, input_size, num_samples, len(gpus))

    mIoU = compute_mean_ioU(parsing_preds, scales, centers, args.num_classes, args.data_dir, input_size)

    print(mIoU)
def main ( ) : args = get_arguments ( ) os . environ [ "CUDA_VISIBLE_DEVICES" ] = args . gpu gpus = [ int ( i ) for i in args . gpu . split ( ',' ) ] h , w = map ( int , args . input_size . split ( ',' ) ) input_size = ( h , w ) model = Res_Deeplab ( num_classes = args . num_classes ) normalize = transforms . Normalize ( mean = [ 0.485 , 0.456 , 0.406 ] , std = [ 0.229 , 0.224 , 0.225 ] ) transform = transforms . Compose ( [ transforms . ToTensor ( ) , normalize , ] ) lip_dataset = LIPDataSet ( args . data_dir , 'val' , crop_size = input_size , transform = transform ) num_samples = len ( lip_dataset ) valloader = data . DataLoader ( lip_dataset , batch_size = args . batch_size * len ( gpus ) , shuffle = False , pin_memory = True ) restore_from = args . restore_from state_dict = model . state_dict ( ) . copy ( ) state_dict_old = torch . load ( restore_from ) for key , nkey in zip ( state_dict_old . keys ( ) , state_dict . keys ( ) ) : if key != nkey : # remove the 'module.' in the 'key' state_dict [ key [ 7 : ] ] = deepcopy ( state_dict_old [ key ] ) else : state_dict [ key ] = deepcopy ( state_dict_old [ key ] ) model . load_state_dict ( state_dict ) model . eval ( ) model . cuda ( ) parsing_preds , scales , centers = valid ( model , valloader , input_size , num_samples , len ( gpus ) ) mIoU = compute_mean_ioU ( parsing_preds , scales , centers , args . num_classes , args . data_dir , input_size ) print ( mIoU )