工作生活

shuffle and select equal dataset

2019-07-04  本文已影响0人  狼无雨雪
import shutil
import os
import glob
import random
basicPath = "/home/t-huch/models/research/slim/data_pnasnet-5_large_equal_valid"
truePath = os.path.join(basicPath, "output_validation_true/*")
falsePath = os.path.join(basicPath, "output_validation_false/*")
rmPath = os.path.join(basicPath, "temp")
if not os.path.exists(rmPath):
    os.makedirs(rmPath)
trueFiles = glob.glob(truePath)
lengthTrueFiles = len(trueFiles)
print("the length of trueFiles is {}".format(lengthTrueFiles))
falseFiles = glob.glob(falsePath)
lengthFalseFiles = len(falseFiles)
print("the length of falseFiles is {}".format(lengthFalseFiles))
the length of trueFiles is 1954
the length of falseFiles is 9630
random.shuffle(trueFiles)
random.shuffle(falseFiles)
if lengthTrueFiles > lengthFalseFiles:
    rmFiles = trueFiles[0:lengthTrueFiles - lengthFalseFiles]
elif lengthFalseFiles > lengthTrueFiles:
    rmFiles = falseFiles[0:lengthFalseFiles - lengthTrueFiles]
_ = [shutil.move(filename, rmPath) for filename in rmFiles]
上一篇 下一篇

猜你喜欢

热点阅读