def test(fileList, model): # prepare prep() fileAm = len(fileList) print('Start testing ......\n') print('Total : %d' % fileAm ) i, j = 0, list(map(int, np.multiply( fileAm, np.multiply(0.1, range(1,11,1)) ))) # test every img for file in fileList: #file = trainPath + file # print progress i = i + 1 if i in j: print( '\t{:.0%}'.format((j.index(i)+1)/10 )) # get predict predict = seg(file, model, trainPath) # get ground truth trueMask = rle_mask(file) # evaluate predict evaluate = evalue( predict, trueMask ) #show2(trueMask, 'true', predict, str(evaluate)) # store img,evaluate storePredict(file.replace(trainPath,''), evaluate) # compute accuracy accuracy = calAccu() return accuracy
def combine(file): seg.seg(file) hsv.hsv(file)
def test2(filename): seg(filename, 0, os.getcwd(), os.getcwd()+'/test')
def my_link(): (wid, hei) = s.seg() time.sleep(5) return render_template('hello1.html', wid=wid, hei=hei)
que = "".join(q['question'].split()) q['answer'] = ans q['question'] = que if len(ans) == 0 or len(que) == 0: continue # --- # if q['answer_span'][0] < 0 or q['answer_span'][1] < 0: # # print(d) # # print(article) # # print(ans) # article = d['article_title']+"。"+article # answer_span = gen_answer_span(article, que, ans) # print(answer_span, q['answer_span']) # if answer_span[0]==-1: # # 这里是抽象型回答,或标注错误的回答。没有办法生成answer_span,一共48个 # pass # q['answer_span'] = answer_span # --- answer_span = gen_answer_span(article, que, ans) q['answer_span'] = answer_span json.dump(data, open(output_file, "w", encoding='utf-8'), ensure_ascii=False) if __name__ == "__main__": # 1. 预处理,修整原文不正常标点符号,保留原文的字符,将标题与原文拼接到一起 # 2. 生成字级别的answer_span,这样可以避免分词错误 # main1(input_file="../../train_data/question.json", output_file="../../train_data/question_with_span.json") # 3. 对question_with_span 的 article question answer进行分词处理。 # 4. 针对字级别的answer_span 设计算法,生成词级别的answer_span seg(input_file="../../train_data/question_with_span.json", output_file="../../train_data/question_with_span_seg.json")
default=0.4) parser.add_argument("--file", help="enter some quality limit", nargs='?', default='miro') parser.add_argument("--unity", help="enter some quality limit", nargs='?', default='D:/PROGFILES/unity/Editor/Unity.exe') # nargs='?', default='D:/programs/unity/Editor/Unity.exe') parser.add_argument("--detail", help="enter some quality limit", action='store_true', default=False) parser.add_argument("--sbsize", type=float, default=512) args = parser.parse_args() BLOCK_SIZE = args.blocksize COLTHRESH = args.colthresh TEXTHRESH = args.texthresh FILE = args.file DETAIL = args.detail MULTI = args.multi SBSIZE = args.sbsize UNITY = args.unity seg.seg(BLOCK_SIZE, COLTHRESH, TEXTHRESH, FILE, DETAIL, MULTI) cb.create_bg(BLOCK_SIZE, COLTHRESH, TEXTHRESH, FILE, DETAIL, MULTI, SBSIZE) #gen3d.gen_3d(BLOCK_SIZE, COLTHRESH, TEXTHRESH, FILE, DETAIL, MULTI, SBSIZE) genunity.gen_unity(BLOCK_SIZE, COLTHRESH, TEXTHRESH, FILE, DETAIL, MULTI, SBSIZE, UNITY)
def words(self): return seg.seg(self.doc)
def handle(self, doc): words = seg.seg(doc) words = normal.filter_stop(words) return words
# - run renameFiles.py setting your_path to the path to RIDGES-Fraktur # - run go.py, but replace the path in the line with "### HERE ###" to the path to RIDGES-Fraktur # - run checkLabels.py replacing letter_data with the path to the letter_data folder in RIDGES-Fraktur # - repeat the above 3 steps for dta19 stopp = 0 # list of book folders in 'data' os.chdir(folderpath) ### HERE ### !!!!!!!!!!! folders = [x for x in os.listdir() if os.path.isdir(os.path.join(os.getcwd(), x))] #folders.remove('letter_data') #for foldername in folders: # for each book folder in 'data' datapath = folderpath+folder # path to img/txt data for this book try: # make folder in 'segmentation/segs' to store morph imgs for this book os.mkdir(seg_dir+foldername) except FileExistsError: pass destpath = seg_dir+foldername # path to save segmented letter imgs for this book for img in [x for x in os.listdir(datapath) if x[-3:] == 'png']: # for each line img in this book/folder try: os.mkdir(datapath+'/temp') # to store word images except FileExistsError: pass wordspath = datapath+'/temp' # to store word images wordSeg(img, datapath, wordspath) # get word segmented images print('wordSeg', img, '~~~~~~~~~~~~~~~~~~~~~~~~~') for wordImg in [x for x in os.listdir(wordspath) if x[-3:] == 'png']: # for each word img in this line print('seg', wordImg) seg(wordImg, 1, wordspath, destpath) # segment letters shutil.rmtree(wordspath) # delete 'temp' folder stopp += 1 if stopp > 8: break labelData(destpath, your_path_here+'/fraktur/testdata/letter_data/') # separate letter imgs into folders
def test2(filename): seg(filename, 0, os.getcwd(), os.getcwd() + '/test') ### execute ### filename = 'white.png' filename = 'rrr.png' filename = 'uu.png' filename = 'uuu_ſeiner.png' filename = 'ess.png' filename = 'ess1_Gelüſte.png' # test1(filename) seg(filename, 1, os.getcwd(), os.getcwd() + '/test') # img, nimg, bin = preprocess(filename) # # _, contours, _ = cv2.findContours(bin.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # contours = sorted(contours, key=lambda ctr: cv2.boundingRect(ctr)[0]) # sort contours in order # contour = contours[0] # cv2.imwrite('bin.png', bin) # # out = np.full_like(bin, 0) # create array of 0s (blacks) # for c in contours: # contour = c # ones = np.ones_like(bin) # create array of 1s (almost blacks) # mask = cv2.drawContours(ones, [contour], 0, 0, -1) # color contour area as 0 # out[mask == 0] = 255 # where mask is 0, change out value to img value # x, y, w, h = cv2.boundingRect(contour) # get bounding box for cropping