Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
tongue-diagnosis
Project
Project
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
zhiyang.zhou
tongue-diagnosis
Commits
ad2619dd
Commit
ad2619dd
authored
Jul 08, 2021
by
zhiyang.zhou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加”软件所的数据的预处理程序“
parent
3c16b603
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
6 deletions
+53
-6
img_dataset.py
img_dataset.py
+52
-5
train_tongue_diagnosis.py
train_tongue_diagnosis.py
+1
-1
No files found.
img_dataset.py
View file @
ad2619dd
...
...
@@ -25,6 +25,8 @@ class Image_DataSet(torch.utils.data.Dataset):
# image = np.expand_dims(source_image.transpose((2, 0, 1)), 0)
if
self
.
transform
is
not
None
:
image
=
self
.
transform
(
source_image
)
if
image
.
shape
[
1
]
<
image
.
shape
[
2
]:
image
=
torch
.
transpose
(
image
,
2
,
1
)
img_file_only
=
imgs
[
index
]
tmpstrs
=
os
.
path
.
splitext
(
img_file_only
)[
0
]
.
split
(
'-'
)
...
...
@@ -68,8 +70,11 @@ def check_label(xlsx_path, img_file, property='舌色'):
if
label
in
property_label_to_idx
:
label
=
property_label_to_idx
[
label
]
else
:
raise
ValueError
(
'error label {}, which not found in property_label_to_idx'
.
format
(
label
))
print
(
'error label {}, which not found in property_label_to_idx'
.
format
(
label
))
# raise ValueError(
# 'error label {}, which not found in property_label_to_idx'.format(label))
label
=
None
return
False
,
tmp_name
,
label
print
(
'I find [{0} → {1}] in [{2}].[{3}]'
.
format
(
tmp_name
,
label
,
sheet_name
,
col_nm2
))
return
True
,
tmp_name
,
label
return
False
,
patient_name
,
None
...
...
@@ -103,11 +108,53 @@ def preprocess_data():
img_file
=
os
.
path
.
join
(
img_path
,
img_files
[
k
])
img_file_only
=
img_files
[
k
]
islabeled
,
name
,
label
=
check_label
(
xlsx_path
,
img_file_only
,
property
=
property
)
if
islabeled
:
if
islabeled
and
label
!=
None
:
if
label
>=
8
:
continue
tmpstrs
=
os
.
path
.
splitext
(
img_file_only
)
dst_img_file_only
=
tmpstrs
[
0
]
+
'-'
+
property
+
'_'
+
str
(
label
)
+
tmpstrs
[
1
]
dst_img_file
=
os
.
path
.
join
(
processed_dir
,
dst_img_file_only
)
copyfile
(
img_file
,
dst_img_file
)
# if __name__ == "__main__":
# preprocess_data()
def
crop_img
():
from
PIL
import
Image
import
re
rootdir
=
'E:
\\
workspace
\\
zhongyi
\\
软件所-第一批数据
\\
JDYT
\\
'
cropeddir
=
'E:
\\
workspace
\\
zhongyi
\\
软件所-第一批数据
\\
croped
\\
'
list
=
os
.
listdir
(
rootdir
)
for
i
in
range
(
0
,
len
(
list
)):
img_file
=
os
.
path
.
join
(
rootdir
,
list
[
i
])
img_hold
=
Image
.
open
(
img_file
)
.
convert
(
'RGB'
)
img_size
=
img_hold
.
size
if
img_size
[
0
]
<
img_size
[
1
]:
w
=
img_size
[
0
]
h
=
img_size
[
1
]
left
=
int
((
0.8
/
3
)
*
w
)
right
=
w
-
left
bottom
=
int
((
9
/
10
)
*
h
)
top
=
bottom
-
1200
box
=
(
left
,
top
,
right
,
bottom
)
else
:
w
=
img_size
[
0
]
h
=
img_size
[
1
]
left
=
int
((
0.8
/
10
)
*
w
)
right
=
left
+
1200
*
1.1
top
=
int
((
0.9
/
3
)
*
h
)
bottom
=
top
+
900
*
1.1
box
=
(
left
,
top
,
right
,
bottom
)
# 开始截取
region
=
img_hold
.
crop
(
box
)
name
=
''
.
join
(
re
.
findall
(
'[
\u4e00
-
\u9fa5
]'
,
list
[
i
]))
name
=
name
+
'-'
+
'croped'
+
'.jpg'
croped_img_file
=
os
.
path
.
join
(
cropeddir
,
name
)
region
.
save
(
croped_img_file
)
if
__name__
==
"__main__"
:
preprocess_data
()
# crop_img()
train_tongue_diagnosis.py
View file @
ad2619dd
...
...
@@ -52,7 +52,7 @@ normalizer = transforms.Normalize(mean=[x / 255.0 for x in [125.3, 123.0, 113.9]
transform_train
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
ToPILImage
(),
transforms
.
Resize
((
2
98
,
2
24
)),
transforms
.
Resize
((
224
)),
# transforms.RandomCrop((224, 224), padding=14),
transforms
.
RandomHorizontalFlip
(),
transforms
.
ToTensor
(),
...
...
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