一、新建环境
在conda中建立一个虚拟环境featup,
conda create -n featup python=3.9
二、开始配置:
我是先下载了FeatUp,之后
pip install -e . -i https://mirrors.aliyun.com/pypi/simple/
但是,突然出错了,说无法安装torch,我就自己动手安装的pytorch,速度嗷嗷快
然后再重新执行
pip install -e . -i https://mirrors.aliyun.com/pypi/simple/
哈哈哈,配置环境完成
三、运行程序
import torch
import torchvision.transforms as T
from PIL import Imagefrom featup.util import norm, unnorm
from featup.plotting import plot_feats, plot_lang_heatmapsinput_size = 224
image_path = "c:/1.jpg"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
use_norm = Truetransform = T.Compose([T.Resize(input_size),T.CenterCrop((input_size, input_size)),T.ToTensor(),norm
])image_tensor = transform(Image.open(image_path).convert("RGB")).unsqueeze(0).to(device)upsampler = torch.hub.load("mhamilton723/FeatUp", 'dinov2', use_norm=use_norm).to(device)
hr_feats = upsampler(image_tensor)
lr_feats = upsampler.model(image_tensor)
plot_feats(unnorm(image_tensor)[0], lr_feats[0], hr_feats[0])
注意这里image_path = "c:/1.jpg"
结果提示:
后来还发现缺很多库:
pip install ftfy
pip install regex
四、成功