Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.pytorch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.pytorch
Merge requests
!4
Resolve "Add GANs"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "Add GANs"
4-add-gans
into
master
Overview
0
Commits
26
Pipelines
8
Changes
23
Merged
Guillaume HEUSCH
requested to merge
4-add-gans
into
master
6 years ago
Overview
0
Commits
26
Pipelines
8
Changes
2
Closes
#4 (closed)
Edited
6 years ago
by
Guillaume HEUSCH
0
0
Merge request reports
Compare
version 6
version 6
78a92c7e
6 years ago
version 5
e6a05829
6 years ago
version 4
b3319f64
6 years ago
version 3
2221e9af
6 years ago
version 2
cac9487c
6 years ago
version 1
dab01b02
6 years ago
master (base)
and
latest version
latest version
a8c468d6
26 commits,
6 years ago
version 6
78a92c7e
24 commits,
6 years ago
version 5
e6a05829
23 commits,
6 years ago
version 4
b3319f64
15 commits,
6 years ago
version 3
2221e9af
14 commits,
6 years ago
version 2
cac9487c
11 commits,
6 years ago
version 1
dab01b02
9 commits,
6 years ago
Show latest version
2 files
+
56
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
bob/learn/pytorch/test/test.py
+
52
−
1
View file @ a8c468d6
Edit in single-file editor
Open in Web IDE
Show full file
@@ -47,7 +47,28 @@ def test_architectures():
generator
=
DCGAN_generator
(
1
)
output
=
generator
.
forward
(
t
)
assert
output
.
shape
==
torch
.
Size
([
1
,
3
,
64
,
64
])
# Conditional GAN
d
=
numpy
.
random
.
rand
(
1
,
3
,
64
,
64
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
d
)
cfm
=
numpy
.
zeros
((
1
,
13
,
64
,
64
),
dtype
=
"
float32
"
)
cfm
[:,
0
,
:,
:]
=
1
cfmt
=
torch
.
from_numpy
(
cfm
)
from
..architectures
import
ConditionalGAN_discriminator
discriminator
=
ConditionalGAN_discriminator
(
13
)
output
=
discriminator
.
forward
(
t
,
cfmt
)
assert
output
.
shape
==
torch
.
Size
([
1
])
g
=
numpy
.
random
.
rand
(
1
,
100
,
1
,
1
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
g
)
oh
=
numpy
.
zeros
((
1
,
13
,
1
,
1
),
dtype
=
"
float32
"
)
oh
[
0
]
=
1
oht
=
torch
.
from_numpy
(
oh
)
from
..architectures
import
ConditionalGAN_generator
discriminator
=
ConditionalGAN_generator
(
100
,
13
)
output
=
discriminator
.
forward
(
t
,
oht
)
assert
output
.
shape
==
torch
.
Size
([
1
,
3
,
64
,
64
])
def
test_transforms
():
@@ -149,3 +170,33 @@ def test_DCGANtrainer():
os
.
remove
(
'
netD_epoch_0.pth
'
)
os
.
remove
(
'
netG_epoch_0.pth
'
)
class
DummyDataSetConditionalGAN
(
Dataset
):
def
__init__
(
self
):
pass
def
__len__
(
self
):
return
100
def
__getitem__
(
self
,
idx
):
data
=
numpy
.
random
.
rand
(
3
,
64
,
64
).
astype
(
"
float32
"
)
sample
=
{
'
image
'
:
torch
.
from_numpy
(
data
),
'
pose
'
:
numpy
.
random
.
randint
(
0
,
13
)}
return
sample
def
test_ConditionalGANTrainer
():
from
..architectures
import
ConditionalGAN_generator
from
..architectures
import
ConditionalGAN_discriminator
g
=
ConditionalGAN_generator
(
100
,
13
)
d
=
ConditionalGAN_discriminator
(
13
)
dataloader
=
torch
.
utils
.
data
.
DataLoader
(
DummyDataSetConditionalGAN
(),
batch_size
=
32
,
shuffle
=
True
)
from
..trainers
import
ConditionalGANTrainer
trainer
=
ConditionalGANTrainer
(
g
,
d
,
[
3
,
64
,
64
],
batch_size
=
32
,
noise_dim
=
100
,
conditional_dim
=
13
)
trainer
.
train
(
dataloader
,
n_epochs
=
1
,
output_dir
=
'
.
'
)
import
os
assert
os
.
path
.
isfile
(
'
fake_samples_epoch_000.png
'
)
assert
os
.
path
.
isfile
(
'
netD_epoch_0.pth
'
)
assert
os
.
path
.
isfile
(
'
netG_epoch_0.pth
'
)
os
.
remove
(
'
fake_samples_epoch_000.png
'
)
os
.
remove
(
'
netD_epoch_0.pth
'
)
os
.
remove
(
'
netG_epoch_0.pth
'
)
Loading