Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
人
人工智能系统实战第三期
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyinkai
人工智能系统实战第三期
Commits
c904d45d
Commit
c904d45d
authored
Oct 30, 2023
by
前钰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
224c7bca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
data_loader.py
人工智能系统实战第三期/实战代码/深度学习项目实战/神经网络实现鸢尾花分类/data_loader.py
+42
-0
No files found.
人工智能系统实战第三期/实战代码/深度学习项目实战/神经网络实现鸢尾花分类/data_loader.py
0 → 100644
View file @
c904d45d
from
torch.utils.data
import
Dataset
from
torch.utils.data
import
Dataset
import
os
import
pandas
as
pd
import
numpy
as
np
import
torch
class
iris_dataload
(
Dataset
):
def
__init__
(
self
,
data_path
:
str
,
transform
=
None
):
self
.
data_path
=
data_path
self
.
transform
=
transform
assert
os
.
path
.
exists
(
data_path
),
"dataset root: {} does not exist."
.
format
(
data_path
)
df
=
pd
.
read_csv
(
self
.
data_path
,
names
=
[
0
,
1
,
2
,
3
,
4
])
d
=
{
'Iris-setosa'
:
0
,
'Iris-versicolor'
:
1
,
'Iris-virginica'
:
2
}
df
[
4
]
=
df
[
4
]
.
map
(
d
)
data
=
df
.
iloc
[:,
0
:
4
]
label
=
df
.
iloc
[:,
4
:]
data
=
np
.
array
(
data
)
data
=
(
data
-
np
.
mean
(
data
)
)
/
np
.
std
(
data
)
label
=
np
.
array
(
label
)
self
.
data
=
torch
.
from_numpy
(
np
.
array
(
data
,
dtype
=
'float32'
)
)
self
.
label
=
torch
.
from_numpy
(
np
.
array
(
label
,
dtype
=
'int64'
)
)
self
.
data_num
=
len
(
label
)
# 存储训练集的所有图片路径
print
(
"{} images were found in the dataset."
.
format
(
self
.
data_num
))
def
__len__
(
self
):
return
self
.
data_num
def
__getitem__
(
self
,
idx
):
self
.
data
=
list
(
self
.
data
)
self
.
label
=
list
(
self
.
label
)
return
self
.
data
[
idx
],
self
.
label
[
idx
]
# if __name__ == '__main__':
# custom_dataset = iris_dataload( "./Iris_data.txt")
# print(custom_dataset)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment