styleGAN记录

前言

最近需要看一些gan相关的工作,所以写个博客记录一下开个坑。

由于也不知道啥时候能写完,这里看到一篇写的还可以的博文,着急的朋友可以移步 从零带你入门stylegan~stylegan3的技术细节



styleGAN v1



styleGAN v2

styleGANv2-tiny 实践博客: https://nn.labml.ai/gan/stylegan/index.html


styleGAN v3

v3是对v2一些细节的优化
https://github.com/NVlabs/stylegan3
v3的代码仓库里也有styleganv2模型。

我尝试过可以运行的环境:

python 3.7.6   torch 1.8.0+cu111  torchvision 0.9.0+cu111

也可以是

Python 3.9.16     torch  1.9.1    torchvision 0.10.1

后者可以使这样

conda create --name stylegan3 python=3.9.16
conda install pytorch=1.9.1 cudatoolkit=11.1 -c pytorch

然后再pip一些包

numpy
requests
click
pillow

可能运行时还会有这个问题: torch.utils.cpp extension.load卡住无响应
可能需要去这个目录下清理一下

/home/【用户名】/.cache/torch_extensions

有可能还要安装低版本的setuptools (没AttributeError: module 'distutils' has no attribute 'version'报错就不用)

pip install setuptools==59.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

可能服务器下载这个东西还有点儿慢, 这个233M的东西下完会被放到 /home/【用户名】/.cache/torch/hub/checkpoints 这里。

https://download.pytorch.org/models/alexnet-owt-7be5be79.pth

还有一个
Downloading: “https://raw.githubusercontent.com/richzhang/PerceptualSimilarity/master/lpips/weights/v0.1/alex.pth” to /home/【用户名】/.cache/torch/hub/checkpoints/alex.pth


btw, 记录一下dataloader collate_fn的用法

from torch.utils.data import Dataset
from PIL import Image
from utils import data_utils
import torch

class MyInferenceDataset(Dataset):

	def __init__(self, root, opts, transform=None, preprocess=None):
		self.paths = sorted(data_utils.make_dataset(root))
		self.transform = transform
		self.opts = opts

	def __len__(self):
		return len(self.paths)

	def __getitem__(self, index):
		from_path = self.paths[index]
		# print('from_path:', from_path)
		from_im = Image.open(from_path).convert('RGB')
		if self.transform:
			from_im = self.transform(from_im)
		# save_image(from_im, 'tmp/{}_from_path.jpg'.format(from_path))
		return from_im, from_path

	@staticmethod
	def collate_fn(batch):
		# 官方实现的default_collate可以参考
		# https://github.com/pytorch/pytorch/blob/67b7e751e6b5931a9f45274653f4f653a4e6cdf6/torch/utils/data/_utils/collate.py
		images, paths = tuple(zip(*batch))
		# images = batch
		images = torch.stack(images, dim=0)
		# print(images.shape)  # torch.Size([2, 3, 224, 224])
		return images, paths

自己数据集的预处理: 深度学习模型试跑(十三):stylegan3

猜你喜欢

转载自blog.csdn.net/weixin_43850253/article/details/129087972