Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pytorch Without Pytorch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Falguni Ghosh
Pytorch Without Pytorch
Commits
9e870cba
Commit
9e870cba
authored
1 year ago
by
Falguni Ghosh
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
29fc39f5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
4_Resnet_Solar_panel_defect_Identification/data.py
+40
-0
40 additions, 0 deletions
4_Resnet_Solar_panel_defect_Identification/data.py
with
40 additions
and
0 deletions
4_Resnet_Solar_panel_defect_Identification/data.py
0 → 100644
+
40
−
0
View file @
9e870cba
from
torch.utils.data
import
Dataset
import
torch
from
pathlib
import
Path
from
skimage.io
import
imread
from
skimage.color
import
gray2rgb
import
numpy
as
np
import
torchvision
as
tv
train_mean
=
[
0.59685254
,
0.59685254
,
0.59685254
]
train_std
=
[
0.16043035
,
0.16043035
,
0.16043035
]
class
ChallengeDataset
(
Dataset
):
# TODO implement the Dataset class according to the description
def
__init__
(
self
,
data
,
mode
):
super
().
__init__
()
self
.
data
=
data
self
.
mode
=
mode
self
.
length
=
None
if
mode
==
"
train
"
:
self
.
_transform
=
tv
.
transforms
.
Compose
(
[
tv
.
transforms
.
ToPILImage
(),
tv
.
transforms
.
RandomHorizontalFlip
(
p
=
0.25
),
tv
.
transforms
.
ToTensor
(),
tv
.
transforms
.
Normalize
(
train_mean
,
train_std
)])
# self._transform = tv.transforms.Compose([tv.transforms.ToPILImage(), tv.transforms.RandomVerticalFlip(p=0.2), tv.transforms.RandomRotation(degrees=30), tv.transforms.GaussianBlur(kernel_size=3), tv.transforms.ToTensor(), tv.transforms.Normalize(train_mean, train_std)])
else
:
self
.
_transform
=
tv
.
transforms
.
Compose
([
tv
.
transforms
.
ToPILImage
(),
tv
.
transforms
.
ToTensor
(),
tv
.
transforms
.
Normalize
(
train_mean
,
train_std
)])
def
__len__
(
self
):
self
.
length
=
self
.
data
.
shape
[
0
]
return
self
.
length
def
__getitem__
(
self
,
index
):
image
=
imread
((
self
.
data
.
iloc
[
index
])[
"
filename
"
])
rgb_image
=
gray2rgb
(
image
)
image_tensor
=
self
.
_transform
(
rgb_image
).
type
(
torch
.
Tensor
)
label
=
(
self
.
data
.
iloc
[
index
])[[
"
crack
"
,
"
inactive
"
]]
label_np
=
label
.
to_numpy
().
astype
(
float
)
label_tensor
=
torch
.
from_numpy
(
label_np
).
type
(
torch
.
Tensor
)
return
image_tensor
,
label_tensor
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