[Detailed explanation of code reproduction Zero-DCE: Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement]

Insert image description here

link summary

1. Article: (CVPR 2020) Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement
2. Link: paper .
3. Link: code .
4. Other bloggers’ recurrence links: link .

Several main problems

1. Check whether the computer has a GPU. If it is not a GPU environment, you need to change the code to a CPU environment.
2. There is no data set in the source code.
3. There is a path problem in the code. If the path is incorrect, the data cannot be loaded.
3. The folder needs to be set as required.
4 . Due to different versions, warnings that appear during code running affect the code running.

Check whether the computer has a GPU: change the code to run in the CPU environment

The code in the paper is in the GPU environment, and is commented under each sentence of code that requires the use of the GPU, so all the commands containing this command need to be changed to CPU
specific modifications:
change ".cuda()" in the code Delete it, or change it to ".cpu()".
The following are just some examples: the "#" in front of it is the source code.

// Myloss.py
        # kernel_left = torch.FloatTensor( [[0,0,0],[-1,1,0],[0,0,0]]).cuda().unsqueeze(0).unsqueeze(0)
        # kernel_right = torch.FloatTensor( [[0,0,0],[0,1,-1],[0,0,0]]).cuda().unsqueeze(0).unsqueeze(0)
        # kernel_up = torch.FloatTensor( [[0,-1,0],[0,1, 0 ],[0,0,0]]).cuda().unsqueeze(0).unsqueeze(0)
        # kernel_down = torch.FloatTensor( [[0,0,0],[0,1, 0],[0,-1,0]]).cuda().unsqueeze(0).unsqueeze(0)
        kernel_left = torch.FloatTensor([[0, 0, 0], [-1, 1, 0], [0, 0, 0]]).unsqueeze(0).unsqueeze(0)
        kernel_right = torch.FloatTensor([[0, 0, 0], [0, 1, -1], [0, 0, 0]]).unsqueeze(0).unsqueeze(0)
        kernel_up = torch.FloatTensor([[0, -1, 0], [0, 1, 0], [0, 0, 0]]).unsqueeze(0).unsqueeze(0)
        kernel_down = torch.FloatTensor([[0, 0, 0], [0, 1, 0], [0, -1, 0]]).unsqueeze(0).unsqueeze(0)

        # weight_diff =torch.max(torch.FloatTensor([1]).cuda() + 10000*torch.min(org_pool - torch.FloatTensor([0.3]).cuda(),torch.FloatTensor([0]).cuda()),torch.FloatTensor([0.5]).cuda())
        weight_diff =torch.max(torch.FloatTensor([1]) + 10000*torch.min(org_pool - torch.FloatTensor([0.3]),torch.FloatTensor([0])),torch.FloatTensor([0.5]))
        # E_1 = torch.mul(torch.sign(enhance_pool - torch.FloatTensor([0.5]).cuda()) ,enhance_pool-org_pool)
        E_1 = torch.mul(torch.sign(enhance_pool - torch.FloatTensor([0.5])), enhance_pool - org_pool)

Under CPU conditions, pin_memory=True needs to be changed to pin_memory=False in the training model.

//  lowlight_train.py
   train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=config.train_batch_size, shuffle=True, num_workers=config.num_workers, pin_memory=True)
	# train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=config.train_batch_size, shuffle=True,num_workers=config.num_workers, pin_memory=False)

There is no training data set in the source code

There is a pre-trained model in the source code of this paper, so there is no training data set and it does not affect the direct test code.
The Epoch99.pth is the pre-trained model. So the training set does not affect the testing.
Insert image description here
Of course, you can also find a data set to add according to the code requirements and train your own pre-trained model.

There is a path problem in the code. If the path is incorrect, the data cannot be loaded.

In the dataloader.py file:
the function is to preprocess the relevant code for data.
".jpg" appears in the file path . If the data in the training set is in PNG format, you need to change the last one to " .png"

// dataloader.py
def populate_train_list(lowlight_images_path):#获取训练列表(微光图像路径)

	# image_list_lowlight = glob.glob(lowlight_images_path + "*.jpg")
	image_list_lowlight = glob.glob(lowlight_images_path + "*.png")

	train_list = image_list_lowlight

	random.shuffle(train_list)

	return train_list

In the lowlight_train.py file:
Change the file path to your own data path
. Either absolute path or relative path can be used.
"You can increase the learning rate and reduce the number of iterations when starting to debug the code. After the code is adjusted, change it to the specified path." parameters, can run faster"

// lowlight_train.py
if __name__ == "__main__":

	parser = argparse.ArgumentParser()

	# Input Parameters
	# parser.add_argument('--lowlight_images_path', type=str, default="data/train_data/")
	parser.add_argument('--lowlight_images_path', type=str, default="E:/image/Zero-DCE-master/Zero-DCE_code/data/train_data/")
	# parser.add_argument('--lr', type=float, default=0.0001)
	# parser.add_argument('--weight_decay', type=float, default=0.0001)
	parser.add_argument('--grad_clip_norm', type=float, default=0.1)
	parser.add_argument('--lr', type=float, default=0.01)
	parser.add_argument('--weight_decay', type=float, default=0.01)
	parser.add_argument('--num_epochs', type=int, default=20)
	# parser.add_argument('--num_epochs', type=int, default=20)
	parser.add_argument('--train_batch_size', type=int, default=8)
	parser.add_argument('--val_batch_size', type=int, default=4)
	parser.add_argument('--num_workers', type=int, default=4)
	parser.add_argument('--display_iter', type=int, default=10)
	parser.add_argument('--snapshot_iter', type=int, default=10)
	parser.add_argument('--snapshots_folder', type=str, default="E:/image/Zero-DCE-master/Zero-DCE_code/snapshots/")
	# parser.add_argument('--snapshots_folder', type=str, default="snapshots/")
	parser.add_argument('--load_pretrain', type=bool, default= False)
	parser.add_argument('--pretrain_dir', type=str, default= "E:/image/Zero-DCE-master/Zero-DCE_code/snapshots/Epoch99.pth")
	# parser.add_argument('--pretrain_dir', type=str, default="snapshots/Epoch99.pth")
	config = parser.parse_args()

Folders need to be set up as required

Set the result folder under the data folder, and set the same two folders under the result file as those under the test_data folder: the DICM and LIME folders must be the same
, otherwise an error will be reported
Insert image description here

Due to different versions, warnings that appear when running the code affect the running of the code.

1. The torch.nn.utils.clip_grad_norm function is deprecated

//  torch.nn.utils.clip_grad_norm函数被弃用 的警告
UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_. 
torch.nn.utils.clip_grad_norm(DCE_net.parameters(),config.grad_clip_norm)

change the law;

//  lowlight_train.py
        # torch.nn.utils.clip_grad_norm(DCE_net.parameters(),config.grad_clip_norm)
   		torch.nn.utils.clip_grad_norm_(DCE_net.parameters(),config.grad_clip_norm)

2. nn.functional.tanh is deprecated

//  nn.functional.tanh被弃用的警告
UserWarning: nn.functional.tanh is deprecated. Use torch.tanh instead.
 warnings.warn("nn.functional.tanh is deprecated. Use torch.tanh instead.")

Change the law

//  model.py
    x5 = self.relu(self.e_conv5(torch.cat([x3,x4],1)))

   	# x5 = self.upsample(x5)
   	x6 = self.relu(self.e_conv6(torch.cat([x2,x5],1)))

   	# x_r = F.tanh(self.e_conv7(torch.cat([x1,x6],1)))  #改之前
   	x_r = torch.tanh(self.e_conv7(torch.cat([x1, x6], 1)))
   	r1,r2,r3,r4,r5,r6,r7,r8 = torch.split(x_r, 3, dim=1)

Guess you like

Origin blog.csdn.net/Alkaidsimon/article/details/131665527