Densefuse
Densefuse的源码位置
github库
我是直接在pytorch1.12.1+cu113上复现的,具体要改哪些可以根据你的报错来看
可以参考这边博客,当然她不全面,建议直接复制我的代码替换后再看还会有什么问题
densefuse-pytorch 图像融合代码复现记录
需要额外安装的扩展
pip install torchfile
pip install scikit-image
测试部分
我这里给出我修改之后的utils.py和test_image.py,这样你至少可以在第一时间跑通测试
utils.py
import os
from os import listdir, mkdir, sep
from os.path import join, exists, splitext
import random
import numpy as np
import torch
from PIL import Image
from torch.autograd import Variable
import torchfile
from args_fusion import args
# from scipy.misc import imread, imsave, imresize
import matplotlib as mpl
import cv2
from torchvision import datasets, transforms
from skimage.transform import resize as imresize
from imageio import imwrite,imread
def list_images(directory):
images = []
names = []
dir = listdir(directory)
dir.sort()
for file in dir:
name = file.lower()
if name.endswith('.png'):
images.append(join(directory, file))
elif name.endswith('.jpg'):
images.append(join(directory, file))
elif name.endswith('.jpeg'):
images.append(join(directory, file))
name1 = name.split('.')
names.append(name1[0])
return images
def tensor_load_rgbimage(filename, size=None, scale=None, keep_asp=False):
img = Image.open(filename).convert('RGB')
if size is not None:
if keep_asp:
size2 = int(size * 1.0 / img.size[0] * img.size[1])
img = img.resize((size, size2), Image.ANTIALIAS)
else:
img = img.resize((size, size), Image.ANTIALIAS)
elif scale is not None:
img = img.resize((int(img.size[0] / scale), int(img.size[1] / scale)), Image.ANTIALIAS)
img = np.array(img).transpose(2, 0, 1)
img = torch.from_numpy(img).float()
return img
def tensor_save_rgbimage(tensor, filename, cuda=True):
if cuda:
# img = tensor.clone().cpu().clamp(0, 255).numpy()
img = tensor

博客记录了Densefuse图像融合代码在Pytorch上的复现过程。作者在pytorch1.12.1+cu113上复现,可根据报错修改代码,还可参考相关博客。此外,给出修改后的utils.py和test_image.py,助读者快速跑通测试。
最低0.47元/天 解锁文章
8888

被折叠的 条评论
为什么被折叠?



