Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Unconditional Diffusion
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Diffusion Project
Unconditional Diffusion
Commits
bbe8a848
Commit
bbe8a848
authored
2 years ago
by
Tobias Seibel
Browse files
Options
Downloads
Patches
Plain Diff
further augmentation added
parent
6ce76635
Branches
ddpm-diffusers
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dataloader/load.py
+18
-5
18 additions, 5 deletions
dataloader/load.py
with
18 additions
and
5 deletions
dataloader/load.py
+
18
−
5
View file @
bbe8a848
...
@@ -4,11 +4,11 @@ from torchvision import transforms
...
@@ -4,11 +4,11 @@ from torchvision import transforms
import
os
import
os
from
PIL
import
Image
from
PIL
import
Image
import
pandas
as
pd
import
pandas
as
pd
import
numpy
as
np
class
UnconditionalDataset
(
Dataset
):
class
UnconditionalDataset
(
Dataset
):
def
__init__
(
self
,
fpath
,
img_size
,
train
,
frac
=
0.8
,
skip_first_n
=
0
,
ext
=
"
.png
"
,
transform
=
True
):
def
__init__
(
self
,
fpath
,
img_size
,
train
,
frac
=
0.8
,
skip_first_n
=
0
,
ext
=
"
.png
"
,
transform
=
True
):
"""
"""
Customized to datasets where all images are within a folder and the filenames are sorted by likeliehood.(Landscape Dataset)
Args:
Args:
fpath (string): Path to the folder where images are stored
fpath (string): Path to the folder where images are stored
img_size (int): size of output image img_size=height=width
img_size (int): size of output image img_size=height=width
...
@@ -42,14 +42,27 @@ class UnconditionalDataset(Dataset):
...
@@ -42,14 +42,27 @@ class UnconditionalDataset(Dataset):
self
.
df
=
df_test
self
.
df
=
df_test
if
transform
:
if
transform
:
self
.
transform
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Normalize
(
mean
=
(
0.5
,
0.5
,
0.5
),
std
=
(
0.5
,
0.5
,
0.5
)),
intermediate_size
=
150
transforms
.
Resize
(
img_size
,
antialias
=
True
),
transforms
.
RandomHorizontalFlip
(
p
=
0.5
)])
theta
=
np
.
pi
/
4
-
np
.
arccos
(
intermediate_size
/
(
np
.
sqrt
(
2
)
*
img_size
))
#Check dataloading.ipynb in analysis-depot for more details
transform_rotate
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Normalize
(
mean
=
(
0.5
,
0.5
,
0.5
),
std
=
(
0.5
,
0.5
,
0.5
)),
transforms
.
Resize
(
intermediate_size
,
antialias
=
True
),
transforms
.
RandomRotation
(
theta
/
np
.
pi
*
180
,
interpolation
=
transforms
.
InterpolationMode
.
BILINEAR
),
transforms
.
CenterCrop
(
img_size
),
transforms
.
RandomHorizontalFlip
(
p
=
0.5
)])
transform_randomcrop
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Normalize
(
mean
=
(
0.5
,
0.5
,
0.5
),
std
=
(
0.5
,
0.5
,
0.5
)),
transforms
.
Resize
(
intermediate_size
),
transforms
.
RandomCrop
(
img_size
),
transforms
.
RandomHorizontalFlip
(
p
=
0.5
)])
self
.
transform
=
transforms
.
RandomChoice
([
transform_rotate
,
transform_randomcrop
])
else
:
self
.
transform
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Resize
(
img_size
)])
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
df
)
return
len
(
self
.
df
)
def
__getitem__
(
self
,
idx
):
def
__getitem__
(
self
,
idx
):
path
=
self
.
df
.
iloc
[
idx
].
Filepath
path
=
self
.
df
.
iloc
[
idx
].
Filepath
s
img
=
Image
.
open
(
path
)
img
=
Image
.
open
(
path
)
return
self
.
transform
(
img
),
0
return
self
.
transform
(
img
),
0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment