Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kiryuu Sakuya
TensorFlow-Homework
Commits
c9c5398f
Unverified
Commit
c9c5398f
authored
Apr 14, 2020
by
Kiryuu Sakuya
🎵
Browse files
Upload exam.1
parent
7193e992
Changes
4
Hide whitespace changes
Inline
Side-by-side
exam/calltest.py
0 → 100644
View file @
c9c5398f
from
subprocess
import
*
import
os
# 执行用户完成的脚本
# call('python step1/preprocessTest.py')
# call('python step2/dataAugmentationTest.py')
# call('python step3/generatorTest.py')
# call('python step4/AlexNetTest.py')
# call('python step5/VGGPreprocessTest.py')
# call('python step6/VGGNetTest.py')
# call('python step7/InceptionTest.py')
# call('python step8/ResNetTest.py')
# call('python step9/outputsUtilsTest.py')
# call('python step10/TrainSaveLoadTest.py')
call
(
'python step10/AnsAlexNet.py'
)
\ No newline at end of file
exam/step1/preprocessCompleted.py
0 → 100644
View file @
c9c5398f
import
cv2
import
os
def
changeSize
(
BasePath
=
'data/testSet'
,
targetPath
=
'data/userOutputs'
):
for
root
,
dirs
,
files
in
os
.
walk
(
BasePath
):
for
fileName
in
files
:
file
=
os
.
path
.
join
(
root
,
fileName
)
try
:
image
=
cv2
.
imread
(
file
)
dim
=
(
224
,
224
)
resized
=
cv2
.
resize
(
image
,
dim
)
if
root
.
endswith
(
'train'
):
targetSet
=
'train_224'
else
:
targetSet
=
'valid_224'
target_path
=
os
.
path
.
join
(
targetPath
,
targetSet
,
fileName
)
cv2
.
imwrite
(
target_path
,
resized
)
except
:
print
(
file
)
print
(
'file error'
)
os
.
remove
(
file
)
if
__name__
==
'__main__'
:
changeSize
()
\ No newline at end of file
exam/step1/preprocessForUsers.py
0 → 100644
View file @
c9c5398f
import
cv2
import
os
def
changeSize
(
BasePath
=
'data/testSet'
,
targetPath
=
'data/userOutputs'
):
'''
请使用os.walk()循环origin目录下的全部文件,使用cv2改变图片尺寸为(224,224)
BasePath中文件夹有两个,分别是‘train’ 和 'valid'
targetPath中文件夹有两个,分别是'train_224'和'valid_224'
图片名可以不变
:param BasePath:原始图片所在路径,类型为str
:param targetPath:处理后图片保存的路径,类型为str
:return:无
'''
#********** Begin **********#
#********** End **********#
if
__name__
==
'__main__'
:
changeSize
()
\ No newline at end of file
exam/step1/preprocessTest.py
0 → 100644
View file @
c9c5398f
import
os
import
filecmp
from
preprocessForUsers
import
changeSize
changeSize
()
correctTrainPath
=
'data/rightOutputs/train_224'
correctValidPath
=
'data/rightOutputs/valid_224'
userTrainPath
=
'data/userOutputs/train_224'
userValidPath
=
'data/userOutputs/valid_224'
usertTrainFile
=
os
.
listdir
(
userTrainPath
)
usertValidFile
=
os
.
listdir
(
userValidPath
)
if
len
(
usertTrainFile
)
\
u003c
=
1
:
print
(
'未能通过本关测试!没有正确生成处理后图片。'
,
end
=
''
)
exit
()
if
len
(
usertValidFile
)
\
u003c
=
1
:
print
(
'未能通过本关测试!没有正确生成处理后图片。'
,
end
=
''
)
exit
()
try
:
for
imgUserTrainName
in
usertTrainFile
:
if
imgUserTrainName
!=
'.gitignore'
:
# 从用户的输出文件中抽取样本,一个是用户输出的训练集,一个是用户输出的验证集
# 获取对应文件名
imgUserTrainPath
=
os
.
path
.
join
(
userTrainPath
,
imgUserTrainName
)
# 找到正确文件中的对应样本的路径
imgCorrectTrainPath
=
os
.
path
.
join
(
correctTrainPath
,
imgUserTrainName
)
bool
=
filecmp
.
cmp
(
imgCorrectTrainPath
,
imgUserTrainPath
)
if
not
bool
:
print
(
'未能通过本关测试!'
,
end
=
''
)
break
else
:
for
imgUserValidName
in
usertValidFile
:
if
imgUserValidName
!=
'.gitignore'
:
# 从用户的输出文件中抽取样本,一个是用户输出的训练集,一个是用户输出的验证集
# 获取对应文件名
imgUserValidPath
=
os
.
path
.
join
(
userValidPath
,
imgUserValidName
)
imgCorrectValidPath
=
os
.
path
.
join
(
correctValidPath
,
imgUserValidName
)
bool
=
filecmp
.
cmp
(
imgCorrectValidPath
,
imgUserValidPath
)
if
not
bool
:
print
(
'未能通过本关测试!'
,
end
=
''
)
break
else
:
print
(
'恭喜你通过本关测试!'
,
end
=
''
)
try
:
os
.
remove
(
'data/userOutputs/valid_224/.gitignore'
)
os
.
remove
(
'data/userOutputs/train_224/.gitignore'
)
except
:
pass
#
except
:
print
(
'未能通过本关测试!'
,
end
=
''
)
\ 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