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
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
Commits
889ced71
Commit
889ced71
authored
6 years ago
by
Anjith GEORGE
Committed by
Olegs NIKISINS
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Modified the data_folder to be more generic
parent
85834fef
No related branches found
No related tags found
1 merge request
!12
Modified the data_folder to be more generic
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/pytorch/datasets/data_folder.py
+12
-12
12 additions, 12 deletions
bob/learn/pytorch/datasets/data_folder.py
with
12 additions
and
12 deletions
bob/learn/pytorch/datasets/data_folder.py
+
12
−
12
View file @
889ced71
...
...
@@ -12,9 +12,8 @@ import torch.utils.data as data
import
os
import
random
random
.
seed
(
a
=
7
)
import
PIL
random
.
seed
(
a
=
7
)
import
numpy
as
np
...
...
@@ -102,7 +101,7 @@ class DataFolder(data.Dataset):
A directory containing the training data.
transform : object
A function/transform that takes in a
PIL
image, and returns a
A function/transform that takes in a
numpy.ndarray
image, and returns a
transformed version. E.g, ``transforms.RandomCrop``. Default: None.
extension : str
...
...
@@ -155,7 +154,7 @@ class DataFolder(data.Dataset):
A directory containing the training data.
transform : object
A function/transform
that takes in a PIL
image, and returns a
A
custom
function/transform
(torchvision.transforms.Compose) that takes in a numpy.ndarray
image
, and returns a
transformed version. E.g, ``transforms.RandomCrop``. Default: None.
extension : str
...
...
@@ -238,9 +237,9 @@ class DataFolder(data.Dataset):
Returns
-------
p
il
_img : Tensor
or PIL I
mage
If ``self.transform`` is defined the output is the torch.Tensor,
otherwise the
output is an instance of the PIL.Image.Image class
.
n
p_img : Tensor
i
mage
If ``self.transform`` is defined
as a custom function,
the output is the torch.Tensor,
otherwise the
last transform in the transforms.Compose should be transforms.ToTensor()
.
target : int
Index of the class.
...
...
@@ -254,20 +253,21 @@ class DataFolder(data.Dataset):
if
isinstance
(
self
.
transform
,
transforms
.
Compose
):
# if an instance of torchvision composed transformation
if
len
(
img_array
.
shape
)
==
3
:
# for color images
if
len
(
img_array
.
shape
)
==
3
:
# for color
or multi-channel
images
img_array_tr
=
np
.
swapaxes
(
img_array
,
1
,
2
)
img_array_tr
=
np
.
swapaxes
(
img_array_tr
,
0
,
2
)
p
il
_img
=
PIL
.
Image
.
fromarray
(
img_array_tr
)
# convert to PIL from array of size (H x W x 3)
n
p_img
=
img_array_tr
.
copy
()
# np_img is numpy.ndarray of shape HxWxC
else
:
# for gray-scale images
pil_img
=
PIL
.
Image
.
fromarray
(
img_array
,
'
L
'
)
# convert to PIL from array of size (H x W)
np_img
=
np
.
expand_dims
(
img_array_tr
,
2
)
# np_img is numpy.ndarray of size HxWx1
if
self
.
transform
is
not
None
:
p
il
_img
=
self
.
transform
(
p
il
_img
)
n
p_img
=
self
.
transform
(
n
p_img
)
# after this transformation np_img should be a tensor
else
:
# if custom transformation function is given
...
...
@@ -275,7 +275,7 @@ class DataFolder(data.Dataset):
return
torch
.
Tensor
(
img_array_transformed
).
unsqueeze
(
0
),
target
# convert array to Tensor, also return target
return
p
il
_img
,
target
return
n
p_img
,
target
#==========================================================================
...
...
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