Skip to content

Commit 5ccef28

Browse files
committed
1.0.1.190122
1 parent dc80cb2 commit 5ccef28

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

Generate_image/README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## 环境准备
22

3-
- 本程序需要安装[PyTorch](https://pytorch.org/) 本人安装总结[地址]()
3+
- 本程序需要安装[PyTorch](https://pytorch.org/) 本人安装总结[地址](https://blog.csdn.net/qq_41654985/article/details/86599016)
44
- 还需要通过`pip install -r requirements.txt` 安装其它依赖
55

66
## 数据
77
标签文件夹下放入图片
88

99
## 用法
10-
如果想要使用visdom可视化,请先运行`python2 -m visdom.server`启动visdom服务
10+
如果想要使用visdom可视化,请先运行`python -m visdom.server`启动visdom服务
1111

1212
基本用法:
1313
```

Generate_image/main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
class Config(object):
1212
data_path = 'data/' # 数据集存放路径
1313
num_workers = 4 # 多进程加载数据所用的进程数
14-
image_size = 224 # 图片尺寸
14+
image_size = 96 # 图片尺寸
1515
batch_size = 32
1616
max_epoch = 4000
17-
lr1 = 2e-4 # 生成器的学习率 2.7*2-4
18-
lr2 = 2e-4 # 判别器的学习率
17+
lr1 = 0.001 # 2e-4 # 生成器的学习率 2.7*2-4
18+
lr2 = 0.001 # 2e-4 # 判别器的学习率
1919
beta1 = 0.5 # Adam优化器的beta1参数
2020
gpu = True # 是否使用GPU
2121
nz = 100 # 噪声维度
@@ -144,8 +144,9 @@ def train(**kwargs):
144144
# 保存模型、图片
145145
tv.utils.save_image(fix_fake_imgs.data[:64], '%s/%s.png' % (opt.save_path, epoch), normalize=True,
146146
range=(-1, 1))
147-
t.save(netd.state_dict(), 'checkpoints/netd_%s.pth' % epoch)
148-
t.save(netg.state_dict(), 'checkpoints/netg_%s.pth' % epoch)
147+
tag = [i for i in os.listdir('./data') if os.path.isdir('./data/' + i)][0]
148+
t.save(netd.state_dict(), 'checkpoints/%s_d_%s.pth' % (tag, epoch))
149+
t.save(netg.state_dict(), 'checkpoints/%s_g_%s.pth' % (tag, epoch))
149150
errord_meter.reset()
150151
errorg_meter.reset()
151152

Generate_image/model.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ class NetG(nn.Module):
99

1010
def __init__(self, opt):
1111
super(NetG, self).__init__()
12-
ngf = opt.ngf # 生成器feature map数
12+
ngf = opt.ngf # 生成器 map数
1313

1414
self.main = nn.Sequential(
15-
# 输入是一个nz维度的噪声,我们可以认为它是一个1*1*nz的feature map
16-
nn.ConvTranspose2d(opt.nz, ngf * 8, 4, 1, 0, bias=False),
15+
# 输入是一个nz维度的噪声,我们可以认为它是一个1*1*nz的 map
16+
nn.ConvTranspose2d(opt.nz, ngf * 8, kernel_size=4, stride=1, padding=0, bias=False),
1717
nn.BatchNorm2d(ngf * 8),
1818
nn.ReLU(True),
1919
# 上一步的输出形状:(ngf*8) x 4 x 4
2020

21-
nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 1, bias=False),
21+
nn.ConvTranspose2d(ngf * 8, ngf * 4, kernel_size=4, stride=2, padding=1, bias=False),
2222
nn.BatchNorm2d(ngf * 4),
2323
nn.ReLU(True),
2424
# 上一步的输出形状: (ngf*4) x 8 x 8
2525

26-
nn.ConvTranspose2d(ngf * 4, ngf * 2, 4, 2, 1, bias=False),
26+
nn.ConvTranspose2d(ngf * 4, ngf * 2, kernel_size=4, stride=2, padding=1, bias=False),
2727
nn.BatchNorm2d(ngf * 2),
2828
nn.ReLU(True),
2929
# 上一步的输出形状: (ngf*2) x 16 x 16
3030

31-
nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 1, bias=False),
31+
nn.ConvTranspose2d(ngf * 2, ngf, kernel_size=4, stride=2, padding=1, bias=False),
3232
nn.BatchNorm2d(ngf),
3333
nn.ReLU(True),
3434
# 上一步的输出形状:(ngf) x 32 x 32
3535

36-
nn.ConvTranspose2d(ngf, 3, 5, 3, 1, bias=False),
36+
nn.ConvTranspose2d(ngf, 3, kernel_size=5, stride=3, padding=1, bias=False),
3737
nn.Tanh() # 输出范围 -1~1 故而采用Tanh
3838
# 输出形状:3 x 96 x 96
3939
)
@@ -52,26 +52,26 @@ def __init__(self, opt):
5252
ndf = opt.ndf
5353
self.main = nn.Sequential(
5454
# 输入 3 x 96 x 96
55-
nn.Conv2d(3, ndf, 5, 3, 1, bias=False),
55+
nn.Conv2d(3, ndf, kernel_size=5, stride=3, padding=1, bias=False),
5656
nn.LeakyReLU(0.2, inplace=True),
5757
# 输出 (ndf) x 32 x 32
5858

59-
nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
59+
nn.Conv2d(ndf, ndf * 2, kernel_size=4, stride=2, padding=1, bias=False),
6060
nn.BatchNorm2d(ndf * 2),
6161
nn.LeakyReLU(0.2, inplace=True),
6262
# 输出 (ndf*2) x 16 x 16
6363

64-
nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
64+
nn.Conv2d(ndf * 2, ndf * 4, kernel_size=4, stride=2, padding=1, bias=False),
6565
nn.BatchNorm2d(ndf * 4),
6666
nn.LeakyReLU(0.2, inplace=True),
6767
# 输出 (ndf*4) x 8 x 8
6868

69-
nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
69+
nn.Conv2d(ndf * 4, ndf * 8, kernel_size=4, stride=2, padding=1, bias=False),
7070
nn.BatchNorm2d(ndf * 8),
7171
nn.LeakyReLU(0.2, inplace=True),
7272
# 输出 (ndf*8) x 4 x 4
7373

74-
nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False),
74+
nn.Conv2d(ndf * 8, 1, kernel_size=4, stride=1, padding=0, bias=False),
7575
nn.Sigmoid() # 输出一个数(概率)
7676
)
7777

Image_recognition/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 环境准备
22

3-
- 本程序需要安装[PyTorch](https://pytorch.org/) 本人安装总结[地址](https:)
3+
- 本程序需要安装[PyTorch](https://pytorch.org/) 本人安装总结[地址](https://blog.csdn.net/qq_41654985/article/details/86599016)
44
- 还需要通过`pip install -r requirements.txt` 安装其它依赖
55

66
## 用法

0 commit comments

Comments
 (0)