Esempio n. 1
0
def test_ssd300_infer():
    context.set_context(mode=context.GRAPH_MODE, device_target="CPU")

    model = Model(ssd300_infer())
    model.compile()
    loc, score = model.predict(ts.ones((1, 3, 300, 300)))
    print(loc.asnumpy(), score.asnumpy())
Esempio n. 2
0
def test_mobilenetv2_infer():
    context.set_context(mode=context.GRAPH_MODE, device_target="CPU")

    model = Model(mobilenetv2_infer())
    model.compile()
    z = model.predict(ts.ones((1, 3, 224, 224)))
    print(z.asnumpy())
Esempio n. 3
0
def test_densenetBC_100():
    context.set_context(mode=context.GRAPH_MODE, device_target="CPU")

    model = Model(densenetBC_100())
    model.compile()
    z = model.predict(ts.ones((1, 3, 32, 32)))
    print(z.asnumpy())
Esempio n. 4
0
def test_sequential():
    context.set_context(mode=context.GRAPH_MODE, device_target="CPU")

    net = layers.SequentialLayer([
        layers.Conv2d(1, 6, 5, pad_mode='valid', weight_init="ones"),
        layers.ReLU(),
        layers.MaxPool2d(kernel_size=2, stride=2)
    ])
    model = Model(net)
    model.compile()
    z = model.predict(ts.ones((1, 1, 32, 32)))
    print(z.asnumpy())
Esempio n. 5
0
def do_eval(dataset=None,
            network=None,
            num_class=2,
            assessment_method="accuracy",
            load_checkpoint_path=""):
    """ do eval """

    if load_checkpoint_path == "":
        raise ValueError(
            "Finetune model missed, evaluation task must load finetune model!")
    net_for_pretraining = network(bert_net_cfg, False, num_class)
    net_for_pretraining.set_train(False)
    model = Model(net_for_pretraining)
    model.load_checkpoint((load_checkpoint_path))

    if assessment_method == "accuracy":
        callback = Accuracy()
    elif assessment_method == "f1":
        callback = F1(False, num_class)
    elif assessment_method == "mcc":
        callback = MCC()
    elif assessment_method == "spearman_correlation":
        callback = SpearmanCorrelation()
    else:
        raise ValueError(
            "Assessment method not supported, support: [accuracy, f1, mcc, spearman_correlation]"
        )

    columns_list = ["input_ids", "input_mask", "segment_ids", "label_ids"]
    for data in dataset.create_dict_iterator():
        input_data = []
        for i in columns_list:
            input_data.append(data[i])
        input_ids, input_mask, token_type_id, label_ids = input_data
        logits = model.predict(input_ids, input_mask, token_type_id, label_ids)
        callback.update(logits, label_ids)
    print("==============================================================")
    eval_result_print(assessment_method, callback)
    print("==============================================================")
Esempio n. 6
0
        eval_net = ssd300_infer(class_num=args_opt.num_classes)
        model = Model(eval_net)
        if args_opt.checkpoint_path:
            model.load_checkpoint(args_opt.checkpoint_path)
        # perform the model predict operation
        print("\n========================================\n")
        print("total images num: ", total)
        print("Processing, please wait a moment...")
        start = time.time()
        pred_data = []
        id_iter = 0
        for data in ds_eval.create_dict_iterator(output_numpy=True):
            image_np = data['image']
            image_shape = data['image_shape']

            output = model.predict(Tensor(image_np))
            for batch_idx in range(image_np.shape[0]):
                pred_data.append({
                    "boxes": output[0].asnumpy()[batch_idx],
                    "box_scores": output[1].asnumpy()[batch_idx],
                    "img_id": id_iter,
                    "image_shape": image_shape[batch_idx]
                })
                id_iter += 1
        cost_time = int((time.time() - start) * 1000)
        print(f'    100% [{total}/{total}] cost {cost_time} ms')
        # calculate mAP for the predict data
        voc_cls = [
            'background', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle',
            'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse',
            'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train',