Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F106002354
Dataloader.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 21, 10:06
Size
2 KB
Mime Type
text/x-python
Expires
Sun, Mar 23, 10:06 (2 d)
Engine
blob
Format
Raw Data
Handle
25094251
Attached To
R13109 LPBF-Sinergia- SNF
Dataloader.py
View Options
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 26 07:14:15 2023
@author: srpv
contact: vigneashwara.solairajapandiyan@empa.ch
contact: vigneashwara.pandiyan@tii.ae
The codes in this following script will be used for the publication of the following work
"Dynamics of in-situ alloying of Ti6Al4V-Fe by means of acoustic emission monitoring
supported by operando synchrotron X-ray diffraction"
@any reuse of this code should be authorized by the first owner, code author
"""
# %%
# Libraries to import
from
torch.utils.data
import
DataLoader
,
Dataset
import
numpy
as
np
import
random
from
torchvision
import
transforms
class
Triplet_loader
(
Dataset
):
def
__init__
(
self
,
df
,
train
=
True
,
transform
=
None
):
self
.
is_train
=
train
self
.
transform
=
transform
self
.
to_pil
=
transforms
.
ToPILImage
()
if
self
.
is_train
:
self
.
images
=
df
.
iloc
[:,
1
:]
.
values
.
astype
(
np
.
uint8
)
self
.
labels
=
df
.
iloc
[:,
0
]
.
values
self
.
index
=
df
.
index
.
values
else
:
self
.
images
=
df
.
iloc
[:,
1
:]
.
values
.
astype
(
np
.
uint8
)
self
.
labels
=
df
.
iloc
[:,
0
]
.
values
self
.
index
=
df
.
index
.
values
def
__len__
(
self
):
return
len
(
self
.
images
)
def
__getitem__
(
self
,
item
):
anchor_img
=
self
.
images
[
item
]
if
self
.
is_train
:
anchor_label
=
self
.
labels
[
item
]
positive_list
=
self
.
index
[
self
.
index
!=
item
][
self
.
labels
[
self
.
index
!=
item
]
==
anchor_label
]
positive_item
=
random
.
choice
(
positive_list
)
positive_img
=
self
.
images
[
positive_item
]
negative_list
=
self
.
index
[
self
.
index
!=
item
][
self
.
labels
[
self
.
index
!=
item
]
!=
anchor_label
]
negative_item
=
random
.
choice
(
negative_list
)
negative_img
=
self
.
images
[
negative_item
]
return
anchor_img
,
positive_img
,
negative_img
,
anchor_label
else
:
label
=
self
.
labels
[
item
]
return
anchor_img
,
label
Event Timeline
Log In to Comment