def createImageLists(imageDir, testingPercentage, validationPercventage):
if not gfile.Exists(imageDir):
print("Image dir'" + imageDir +"'not found.'")
return None
result = {}
subDirs = [x[0] for x in gfile.Walk(imageDir)]
isRootDir = True
for subDir in subDirs:
if isRootDir:
isRootDir = False
continue
extensions = ['jpg', 'jpeg', 'JPG', 'JPEG']
fileList = []
dirName = os.path.basename(subDir)
if dirName == imageDir:
continue
print("Looking for images in '" + dirName + "'")
for extension in extensions:
fileGlob = os.path.join(imageDir, dirName, '*.' + extension)
fileList.extend(gfile.Glob(fileGlob))
if not fileList:
print('No file found')
continue
labelName = re.sub(r'[^a-z0-9]+', ' ', dirName.lower())
trainingImages = []
testingImages =[]
validationImages = []
for fileName in fileList:
baseName = os.path.basename(fileName)
hashName = re.sub(r'_nohash_.*$', '', fileName)
hashNameHased = hashlib.sha1(compat.as_bytes(hashName)).hexdigest()
percentHash = ((int(hashNameHased, 16) %
(MAX_NUM_IMAGES_PER_CLASS + 1)) *
(100.0 / MAX_NUM_IMAGES_PER_CLASS))
if percentHash < validationPercventage:
validationImages.append(baseName)
elif percentHash < (testingPercentage + validationPercventage):
testingImages.append(baseName)
else:
trainingImages.append(baseName)
result[labelName] = {
'dir': dirName,
'training': trainingImages,
'testing': testingImages,
'validation': validationImages,
}
return result
First_Purification.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录