'''filein = r'/home/liming/code/get_mat/ballet_106_1_0_with.png' filein2 = r'/home/liming/code/get_mat/ballet_106_1_0_with_mask.png' width = 100 height = 32 type = 'png' ResizeImage(filein, 'input.png', width, height, type) ResizeImage(filein2, 'mask.png', width, height, type)''' # 最终将图片保存至哪里 result_path = '../net_result3d_64bs' if not os.path.exists(result_path): os.mkdir(result_path) criterion = nn.MSELoss() model = resNet.resnext50(num_classes=9600) model = model.cuda() model = nn.DataParallel(model) image = Image.open('input.png').convert('RGB') image = loader(image).unsqueeze(0) input = image.to(t.float) image = Image.open('mask.png').convert('RGB') image = loader(image).unsqueeze(0) mask = image.to(t.float) # mask = mask[0][2] # mask = mask[:,2,:,:] # print(mask.size()) input = input.cuda()
nc = 4 criterion = nn.MSELoss() # custom weights initialization called on crnn def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: m.weight.data.normal_(0.0, 0.02) elif classname.find('BatchNorm') != -1: m.weight.data.normal_(1.0, 0.02) m.bias.data.fill_(0) model_mask = resNet.resnext50(num_classes=3200) model_bb = crnn.CRNN(opt.imgH, nc, nclass, opt.nh) model_bb.apply(weights_init) if opt.pretrained != '': print('loading pretrained model from %s' % opt.pretrained) model_bb.load_state_dict(torch.load(opt.pretrained)) print(model_bb) image_rgb = torch.FloatTensor(opt.batchSize, 3, opt.imgH, opt.imgW) image_2channel = torch.FloatTensor(opt.batchSize, 2, opt.imgH, opt.imgW) bb = torch.FloatTensor(opt.batchSize, 26, 8) '''text = torch.IntTensor(opt.batchSize * 5) length = torch.IntTensor(opt.batchSize)''' if opt.cuda: model_mask.cuda()