Пример #1
0
def load_model():
    sess = tf.InteractiveSession()
    _, predictModel = dbnet()
    model = predictModel
    model.load_weights('models/model.h5', by_name=True, skip_mismatch=True)
    config = CropConfig("card", 1, 1)
    model_crop = modellib.MaskRCNN(mode="inference",
                                   model_dir="logs",
                                   config=config)
    model_crop.load_weights("model_card/mask_rcnn_card_0030.h5", by_name=True)
    graph = tf.get_default_graph()
    return model, graph, sess, model_crop
        if sside < 5:
            continue

        box[:, 0] = np.clip(np.round(box[:, 0] / width * dest_width), 0,
                            dest_width)
        box[:, 1] = np.clip(np.round(box[:, 1] / height * dest_height), 0,
                            dest_height)
        boxes.append(box.tolist())
        scores.append(score)
    return boxes, scores


if __name__ == '__main__':
    mean = np.array([103.939, 116.779, 123.68])

    _, model = dbnet()
    model.load_weights(
        '/home/nduforet/Projects/Notebooks/DifferentiableBinarization/checkpoints/2020-01-29/simpler_01_0.4214_0.7732.h5',
        by_name=True,
        skip_mismatch=True)
    for image_path in glob.glob(
            osp.join('datasets/total_text_subsample/test_images', '*.jpg')):
        image = cv2.imread(image_path)
        src_image = image.copy()
        h, w = image.shape[:2]
        image = resize_image(image)
        image = image.astype(np.float32)
        image -= mean
        image_input = np.expand_dims(image, axis=0)
        p = model.predict(image_input)[0]
        print(p)
Пример #3
0
if not osp.exists(checkpoints_dir):
    os.makedirs(checkpoints_dir)

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)

train_generator = generate(
    '/new_home/xxiao/DB_with_normal_DCN/datasets/report',
    batch_size=batch_size,
    is_training=True)
val_generator = generate('/new_home/xxiao/DB_with_normal_DCN/datasets/report',
                         batch_size=batch_size,
                         is_training=False)

model, prediction_model = dbnet()
# resnet_filename = 'ResNet-50-model.keras.h5'
# resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename)
# resnet_filepath = get_file('/new_home/xxiao/DifferentiableBinarization_TF/models/db_48_2.0216_2.5701.h5', resnet_resource, cache_subdir='models',
#                            md5_hash='3e9f4e4f77bbe2c9bec13b53ee1c2319')
model.load_weights(
    '/new_home/xxiao/DifferentiableBinarization_TF/models/first_1.7646_2.0746.h5',
    by_name=True,
    skip_mismatch=True)
# model.compile(optimizer=optimizers.Adam(lr=1e-3), loss={'db_loss': lambda y_true, y_pred: y_pred})
model.compile(optimizer=optimizers.SGD(lr=1e-4, momentum=0.8, decay=1e-6),
              loss={
                  'db_loss': lambda y_true, y_pred: y_pred
              })
checkpoint = callbacks.ModelCheckpoint(osp.join(
    checkpoints_dir, 'db_{epoch:02d}_{loss:.4f}_{val_loss:.4f}.h5'),