ymins.append(ymin) xmaxs.append(xmax) ymaxs.append(ymax) return img, labels, xmins, ymins, xmaxs, ymaxs if __name__ == "__main__": task = 'safe' showType = 'all' WTS_PATH = getattr(COCO, 'model_{}'.format(task)) CFG_PATH = WTS_PATH.replace('.pkl', '.yaml') modelName = WTS_PATH.split('/')[-1].split('.')[0] labelmap = getattr(COCO, 'labelmap_{}'.format(task)) inImg = '/DATACENTER4/hao.yang/project/Qin/data/imgs/safe/safe_FMXX_img/' tarXmlDir = '/DATACENTER4/hao.yang/project/Qin/data/xmls/safe/modelXml_safe_FMXX' FILES.rm_mkdir(tarXmlDir) referXml = "/DATACENTER4/hao.yang/common/refer.xml" if hasattr(COCO, 'showNames_{}'.format(task)): showNames = getattr(COCO, 'showNames_{}'.format(task))[showType] else: showNames = [] countNothing = 0 font = cv2.FONT_HERSHEY_SIMPLEX testModel = modelTool.modelTool() testModel.initModel(CFG_PATH, WTS_PATH, labelmap) paletteSet = [(247, 79, 223), (0, 255, 255), (255, 247, 0), (200, 130, 2), (255, 255, 255), (30, 170, 180), (102, 0, 204), (44, 125, 222), (0, 255, 0), (1, 208, 169), (130, 232, 255), (204, 153, 255), (0, 0, 192), (134, 225, 1), (142, 208, 169), (115, 160, 110)] palette = {}
'hole': 0.3, 'tube': 0.3, 'gray': -10, 'vehicle': 1 } forceFetch = [] print(weight) imgDir = '/disk2/hao.yang/project/Qin/data/preProcess/extractFrame/0525/0525_unload_total/0525_unloadAll_total_spec/' xmlDir = '/disk2/hao.yang/project/Qin/data/preProcess/extractFrame/0525/0525_unload_total/0525_unloadAll_total_spec/' if imgDir[-1] == '/': abandonDir = imgDir[:-1] + "_abandon" difDir = imgDir[:-1] + "_dif" else: abandonDir = imgDir + "_abandon" difDir = imgDir + "_dif" FILES.rm_mkdir(abandonDir) FILES.rm_mkdir(difDir) allXmls = [x for x in FILES.get_sorted_files(xmlDir) if '.xml' in x] begin = 0 labelNumber = 0 difNumber = 0 resume = 0 for xmlName in tqdm(allXmls): checkName = xmlName if resume < 0: resume += 1 continue if begin == 0: baseName = checkName begin = 1 continue
if area < MinA: MinA = area shutil.copy(xmlPath, aMinPath) print("cate: {} MinW={}, MinH={}, MinA={}".format(cate, MinW, MinH, MinA)) def find_xmls_with_minimal_size_of_each_cate(xmlDir): allCates = find_all_cates(xmlDir) for cate in allCates: find_xmls_with_minimal_size_of_this_cate(xmlDir, cate) if __name__ == "__main__": xmlDir = r'/DATACENTER4/hao.yang/project/Qin/data/xmls/checkout/xml_checkout_10972_total/' tarDir = '/DATACENTER4/hao.yang/project/Qin/data/xmls/checkout/pos_use/' FILES.rm_mkdir(tarDir) # Uncomment to find some xmls containing all categories and copy matching jpgs # find_xmls_with_all_cates(xmlDir) # Uncomment to find xmls and jpgs containing given cates cates = ['pos_use'] # filter_short_cates(xmlDir,cates) filter_xmls_with_cates(xmlDir, cates) # move_xmls_with_cates(xmlDir,cates) # filter_xmls_without_cates(xmlDir,cates) # Uncomment to find boxes with minimal area, minimal width and minimal height of each category # find_xmls_with_minimal_size_of_each_cate(xmlDir) # Uncomment to filter xml and jpg whose amount of label_person > label_helmet # filter_lack_helmet(xmlDir) # Uncomment to copy jpgs referring xmls jpgDir = r"/DATACENTER4/hao.yang/project/Qin/data/imgs/checkout/imgs_labeled_all_10972/" jpgTar = tarDir
# dirpath="/DATACENTER5/hao.yang/dataRoom/Qin/park/caotan/longVideoFrames/8/" if os.path.exists(dirpath): difdirpath = dirpath.replace('extractFrame', 'removedSimilarityFrame') # if difdirpath[-1]=='/': # difdirpath=difdirpath[:-1]+"Unique"+str(int(SIMIBOUND*1000)) # else: # difdirpath=difdirpath+"Unique"+str(int(SIMIBOUND*1000)) if dirCount < startdir: dirCount += 1 continue if dirCount > enddir: break begin = 0 restart = 1 FILES.rm_mkdir(difdirpath) allFILES = FILES.get_sorted_files(dirpath) jpgsCount = len(allFILES) for file in allFILES: if ".jpg" in file: # basePath='/DATACENTER5/hao.yang/dataRoom/Qin/trade/zhangbabeilu/29AD13E0_1552790204_1_000061.jpg' checkPath = os.path.join(dirpath, file) # print(checkPath) if 'shgjihsjkghj' in file: restart = 1 if restart == 0: continue if begin == 0: difpath = os.path.join(difdirpath, file) shutil.copy(checkPath, difpath) basePath = checkPath
namei = 0 members = ['ph', 'xgt', 'yxy', 'zt', 'hyd', 'hjc'] membersLimits = { 'ph': 267, 'xgt': 318, 'yxy': 360, 'zt': 259, 'hyd': 276, 'hjc': 413 } taskImg = r'E:\factory\voc\helmet_img' taskXml = r'E:\factory\voc\labeled_xml_lackHel\xml' outRoot = r'E:\factory\voc\labeled_xml_lackHel_assignTask' for member in members: outDir = outRoot + '/' + member FILES.rm_mkdir(outDir) FILES.mkdir(outDir + '/img') FILES.mkdir(outDir + '/xml') allXmls = FILES.get_sorted_files(taskXml) random.shuffle(allXmls) memberI = 0 memberF = 0 for xml in allXmls: print(memberI) member = members[memberI] desDir = outRoot + '/' + member xmlPath = taskXml + '/' + xml desXml = desDir + '/xml/' + xml jpg = xml.split('.')[0] + '.jpg' jpgPath = taskImg + '/' + jpg desJpg = desDir + '/img/' + jpg
print(THRESH) print(weight) imgDir = '/DATACENTER2/ke.cao/oil_video_Data/unload_images_dif_day/day_1/' xmlDir = '/DATACENTER2/ke.cao/oil_video_Data/unload_images_dif_day/day_1_xml_fixed/' if imgDir[-1] == '/': errorDir = imgDir[:-1] + "_error" difDir = imgDir[:-1] + "_dif" else: errorDir = imgDir + "_error" difDir = imgDir + "_dif" if xmlDir[-1] == '/': difXmlDir = xmlDir[:-1] + "_dif" else: difXmlDir = xmlDir + "_dif" print(xmlDir) FILES.rm_mkdir(difXmlDir) FILES.rm_mkdir(difDir) # allXmls=[x for x in FILES.get_sorted_files(xmlDir) if '.xml' in x] allXmls = [ x.replace('.jpg', '.xml') for x in FILES.get_sorted_files(imgDir) if '.jpg' in x ] begin = 0 labelNumber = 0 difNumber = 0 resume = 0 t = 0 baseTitle = 'baseTitle' print(len(allXmls)) for xmlName in tqdm(allXmls): curTitle = xmlName.split('_000')[0]
for refer in allRefers: file = refer.split('.')[0] + FileForm sourPath = os.path.join(FileDir, file) tarPath = os.path.join(xmlTar, file) try: shutil.copy(sourPath, tarPath) except: pass xmlDir = r"E:\factory\voc\add_data\summary\rawImg\Tank_jl" jpgDir = r"E:\research\lackLabel\voc\img4206" xmlTar = r"E:\factory\voc\add_data\summary\rawImg\Tank_jl_lite" jpgTar = r"E:\research\lackLabel\voc\img2103_1" remainNum = 70 FILES.rm_mkdir(xmlTar) # FILES.rm_mkdir(jpgTar) allFiles = FILES.get_sorted_files(xmlDir) filesCount = len(allFiles) REMRATE = filesCount / remainNum remRate = REMRATE count = int(REMRATE) + 1 fileNum = 0 for file in allFiles: if count - remRate > 0: filePath = xmlDir + '/' + file tarPath = xmlTar + '/' + file shutil.copy(filePath, tarPath) fileNum += 1 remRate += REMRATE count += 1
#encoding=utf-8 'assign img & xml task to members' import os import shutil import random # personal lib from basicFun import FILES if __name__ == "__main__": namei = 0 members = ['hs', 'yy', 'wzx', 'lf', 'dxj', 'zzh'] taskImg = r'/disk3/hao.yang/project/Qin/dataRoom/XiWan/safe/img/' taskXml = r'/disk3/hao.yang/project/Qin/dataRoom/XiWan/safe/xml/' outRoot = r'/disk3/hao.yang/project/Qin/dataRoom/XiWan/safe/labelTaskAssign_safe_XiWan/' FILES.rm_mkdir(outRoot) for member in members: outDir = os.path.join(outRoot, member) FILES.mkdir(outDir) allXmls = FILES.get_sorted_files(taskXml) for xml in [x for x in allXmls if 'xml' in x]: desDir = os.path.join(outRoot, members[namei]) xmlPath = os.path.join(taskXml, xml) desXml = os.path.join(desDir, xml) # copy file shutil.copy(xmlPath, desXml) namei += 1 if namei == len(members): namei = 0 # disorder members list to increase randomness random.shuffle(members) for member in members: outDir = os.path.join(outRoot, member)
if modelObj['name'] not in bigNames: matchLabel = copy.deepcopy(modelObj) # differ=1 newObjs.append(matchLabel) for labelObj in restLabels: newObjs.append(labelObj) return differ, newObjs imgDir = r'/DATACENTER4/hao.yang/project/Qin/data/imgs/safe/safe_FMXX_img/' # modelXmlDir=imgDir[:-1]+'_modelxml_baseline4' modelXmlDir = '/DATACENTER4/hao.yang/project/Qin/data/xmls/safe/modelXml_safe_FMXX/' labelXmlDir = r'/DATACENTER4/hao.yang/project/Qin/data/xmls/safe/safe_FMXX_22983_total/' badDir = '/DATACENTER4/hao.yang/project/Qin/data/xmls/safe/bad_safe_FMXX/' checkedDir = '/' FILES.rm_mkdir(badDir) nocareKinds = ['cashbox_close', 'cashbox_open', 'safe_hide', 'jug'] bigNames = [] # bigNames不可能有漏标,如果漏掉,必然是故意的,所以不算错误 count = 0 allChecked = [x for x in FILES.get_sorted_files(checkedDir) if ".xml" in x] if allChecked: allXmls = [ x for x in FILES.get_sorted_files(labelXmlDir) if ".xml" in x and x not in allChecked ] else: allXmls = [x for x in FILES.get_sorted_files(modelXmlDir) if ".xml" in x] for xml in tqdm(allXmls): labelXmlPath = os.path.join(labelXmlDir, xml) modelXmlPath = os.path.join(modelXmlDir, xml)