a, b, newBoxes = show(jpgPath[9]) print(newBoxes) #anchors = cluster.anchors # anchors = '8,9, 8,18, 8,31, 8,59, 8,124, 8,351, 8,509, 8,605, 8,800' anchors = '8,24, 8,31, 8,37, 8,42, 8,47, 8,53, 8,58, 8,65, 8,73' anchors = [float(x) for x in anchors.split(',')] anchors = np.array(anchors).reshape(-1, 2) num_anchors = len(anchors) class_names = [ 'none', 'text', ] ##text num_classes = len(class_names) textModel = yolo_text(num_classes, anchors, train=True) textModel.load_weights( 'F:/project/chineseocrmodels/models/text.h5') ##加载预训练模型权重 trainLoad = data_generator(jpgPath[:num_train], anchors, num_classes, splitW) testLoad = data_generator(jpgPath[num_train:], anchors, num_classes, splitW) log_dir = "logs/" batch_size = 64 # textModel.summary() #打印模型概述信息 epochs = 100 print(len(textModel.layers)) textModel.trainable = True
""" from config import kerasTextModel,IMGSIZE,keras_anchors,class_names,GPU,GPUID from text.keras_yolo3 import yolo_text,box_layer,K from helper.image import resize_im,letterbox_image from PIL import Image import numpy as np import tensorflow as tf graph = tf.get_default_graph()##解决web.py 相关报错问题 anchors = [float(x) for x in keras_anchors.split(',')] anchors = np.array(anchors).reshape(-1, 2) num_anchors = len(anchors) num_classes = len(class_names) textModel = yolo_text(num_classes,anchors) textModel.load_weights(kerasTextModel) sess = K.get_session() image_shape = K.placeholder(shape=(2, ))##图像原尺寸:h,w input_shape = K.placeholder(shape=(2, ))##图像resize尺寸:h,w box_score = box_layer([*textModel.output,image_shape,input_shape],anchors, num_classes) def text_detect(img,prob = 0.05): im = Image.fromarray(img) scale = IMGSIZE[0] w,h = im.size w_,h_ = resize_im(w,h, scale=scale, max_scale=2048)##短边固定为608,长边max_scale<4000