Ejemplo n.º 1
0
def stop():
    res = AsyncTask.stop("scoring")

    # Try to clear cuda cache
    if torch.cuda.is_available():
        torch.cuda.empty_cache()
    return res
Ejemplo n.º 2
0
def run_model(
    model: str, params: Optional[dict] = None, run_sync: Optional[bool] = False, enqueue: Optional[bool] = False
):
    request = {"model": model} if model else {}
    res, detail = AsyncTask.run("train", request=request, params=params, force_sync=run_sync, enqueue=enqueue)
    if res is None:
        raise HTTPException(status_code=429, detail=detail)
    return res
Ejemplo n.º 3
0
def run(params: Optional[dict] = None, run_sync: Optional[bool] = False):
    instance: MONAILabelApp = app_instance()
    result = {}
    for method in instance.info()["scoring"]:
        request = {"method": method}
        if params and params.get(method):
            request.update(params[method])
        res, detail = AsyncTask.run("scoring", request=request, params=params, force_sync=run_sync, enqueue=True)
        result[method] = {"result": res, "detail": detail}
    return result
Ejemplo n.º 4
0
def run(params: Optional[dict] = None, run_sync: Optional[bool] = False):
    instance: MONAILabelApp = app_instance()
    result = {}
    for model in instance.info()["trainers"]:
        request = {"model": model}
        if params and params.get(model):
            request.update(params[model])
        res, detail = AsyncTask.run("train", request=request, params=params, force_sync=run_sync, enqueue=True)
        result[model] = {"result": res, "detail": detail}
    return result
Ejemplo n.º 5
0
def run(
    model: str,
    images: Optional[BatchInferImageType] = BatchInferImageType.IMAGES_ALL,
    params: Optional[dict] = None,
    run_sync: Optional[bool] = False,
):
    request = {"model": model, "images": images}
    res, detail = AsyncTask.run("batch_infer", request=request, params=params, force_sync=run_sync)
    if res is None:
        raise HTTPException(status_code=429, detail=detail)
    return res
Ejemplo n.º 6
0
    def async_batch_infer(self,
                          model,
                          images: BatchInferImageType,
                          params=None):
        if self._server_mode:
            request = {"model": model, "images": images}
            res, _ = AsyncTask.run("batch_infer",
                                   request=request,
                                   params=params)
            return res

        url = f"/batch/infer/{model}?images={images}"
        return self._local_request(url, params, "Batch Infer")
Ejemplo n.º 7
0
    def async_scoring(self, method, params=None):
        if not method and not self._scoring_methods:
            return {}

        methods = [method] if method else list(self._scoring_methods.keys())
        result = {}
        for m in methods:
            if self._server_mode:
                request = {"method": m}
                request.update(params[m] if params and params.get(m) else {})
                res, _ = AsyncTask.run("scoring",
                                       request=request,
                                       params=params,
                                       enqueue=True)
                result[m] = res
            else:
                url = f"/scoring/{m}"
                p = params[m] if params and params.get(m) else None
                result[m] = self._local_request(url, p, "Scoring")
        return result[method] if method else result
Ejemplo n.º 8
0
    def async_training(self, model, params=None, enqueue=False):
        if not model and not self._trainers:
            return {}

        models = [model] if model else list(self._trainers.keys())
        enqueue = True if model > 1 else enqueue
        result = {}
        for m in models:
            if self._server_mode:
                request = {"model": m}
                request.update(params[m] if params and params.get(m) else {})
                res, _ = AsyncTask.run("train",
                                       request=request,
                                       params=params,
                                       enqueue=enqueue)
                result[m] = res
            else:
                url = f"/train/{model}?enqueue={enqueue}"
                p = params[m] if params and params.get(m) else None
                result[m] = self._local_request(url, p, "Training")
        return result[model] if model else result
Ejemplo n.º 9
0
def run_method(method: str, params: Optional[dict] = None, run_sync: Optional[bool] = False):
    res, detail = AsyncTask.run("scoring", request={"method": method}, params=params, force_sync=run_sync)
    if res is None:
        raise HTTPException(status_code=429, detail=detail)
    return res
Ejemplo n.º 10
0
def status(all: bool = False, check_if_running: bool = False):
    res, detail = AsyncTask.status("scoring", all, check_if_running)
    if res is None:
        raise HTTPException(status_code=404, detail=detail)
    return res