Пример #1
0
async def plot_curves(class_id: int = Form(...), model_name: str = Form(None)):
    model_op_obj = Model_output(model_path=model_name,
                                first_time=False,
                                is_plot=True)
    path1, path2, path3 = model_op_obj.plot_curves(class_id)

    return {
        "precision_vs_recall_path": SERVER_BASE_URL + path1,
        "precision_recall_vs_confidence_path": SERVER_BASE_URL + path2,
        "roc_curve_path": SERVER_BASE_URL + path3,
    }
Пример #2
0
async def get_most_confused_classes(model_name: str = Form(...),
                                    no_most: Optional[int] = Form(None)):
    model_op_obj = Model_output(model_path=model_name,
                                first_time=False,
                                is_plot=False,
                                is_run=False,
                                is_most_conf_classes=True)

    return {
        "most_confused_classes":
        model_op_obj.most_confused_classes(no_most=no_most)
    }
Пример #3
0
async def generate_heatmap(
        model_name: str = Form(...),
        image: Optional[UploadFile] = File(None),
        img_path: Optional[str] = Form(None),
):
    model_op_obj = Model_output(model_path=model_name,
                                first_time=False,
                                is_plot=False,
                                is_run=True)

    if img_path:
        image = cv2.imread(img_path.split(SERVER_BASE_URL)[1])
    else:
        image = load_image_into_numpy_array(await image.read())

    path = model_op_obj.generate_heatmap(image)

    return {"path": SERVER_BASE_URL + path}
Пример #4
0
async def test_model(
        model_name: str = Form(...),
        image: Optional[UploadFile] = File(None),
        img_path: Optional[str] = Form(None),
):
    model_op_obj = Model_output(model_path=model_name,
                                first_time=False,
                                is_plot=False,
                                is_run=True)

    if img_path:
        image = cv2.imread(img_path.split(SERVER_BASE_URL)[1])
    else:
        image = load_image_into_numpy_array(await image.read())

    onx, ony = model_op_obj.test_model(image)

    return {"x": onx, "y": ony}
Пример #5
0
async def pred_model_output(model: Optional[UploadFile] = File(None),
                            model_name: Optional[str] = Form(None)):
    first_time = model_name is None

    if first_time:
        if model is None:
            raise HTTPException(status_code=400,
                                detail="Model has to be uploaded or selected")

        model_name = str(uuid.uuid1()) + "_" + model.filename

        with open("models/" + model_name, "wb") as buffer:
            shutil.copyfileobj(model.file, buffer)

    model_op_obj = Model_output(model_name, first_time)

    output = {}

    if first_time:
        output = {"model_name": model_name}

    train_metrics, test_metrics = model_op_obj.get_metrics()
    output["train_metrics"] = train_metrics
    output["test_metrics"] = test_metrics

    output["top_5_classes"] = model_op_obj.top_5_classes(SERVER_BASE_URL +
                                                         "test_dataset/")

    output["wrong_pred"] = model_op_obj.wrong_pred()

    output["confusion_matrix_path"] = SERVER_BASE_URL + model_op_obj.confusion(
    )

    x, y = model_op_obj.worst_acc_classes()
    output["wrost_acc_classes"] = {"x": x, "y": y}

    output["most_confused_classes"] = model_op_obj.most_confused_classes()

    output["conf_matrix"] = model_op_obj.get_conf_matrix()

    return output