monailabel.client.client module¶
- class monailabel.client.client.MONAILabelClient(server_url, tmpdir=None, client_id=None)[source]¶
Bases:
object
Basic MONAILabel Client to invoke infer/train APIs over http/https
- Parameters
server_url – Server URL for MONAILabel (e.g. http://127.0.0.1:8000)
tmpdir – Temp directory to save temporary files. If None then it uses tempfile.tempdir
client_id – Client ID that will be added for all basic requests
- __init__(server_url, tmpdir=None, client_id=None)[source]¶
- Parameters
server_url – Server URL for MONAILabel (e.g. http://127.0.0.1:8000)
tmpdir – Temp directory to save temporary files. If None then it uses tempfile.tempdir
client_id – Client ID that will be added for all basic requests
- auth_token(username, password)[source]¶
Fetch Auth Token. Currently only basic authentication is supported.
- Parameters
username – UserName for basic authentication
password – Password for basic authentication
- create_session(image_in, params=None)[source]¶
Create New Session
- Parameters
image_in – filepath for image to be sent to server as part of session creation
params – additional JSON params as part of session reqeust
- Returns
json response which contains session id and other details
- get_session(session_id)[source]¶
Get Session
- Parameters
session_id – Session Id
- Returns
json response which contains more details about the session
- infer(model, image_id, params, label_in=None, file=None, session_id=None)[source]¶
Run Infer
- Parameters
model – Name of Model
image_id – Image Id
params – Additional configs/json params as part of Infer request
label_in – File path for label mask which is needed to run Inference (e.g. In case of Scribbles)
file – File path for Image (use raw image instead of image_id)
session_id – Session ID (use existing session id instead of image_id)
- Returns
response_file (label mask), response_body (json result/output params)
- next_sample(strategy, params)[source]¶
Get Next sample
- Parameters
strategy – Name of strategy to be used for fetching next sample
params – Additional JSON params as part of strategy request
- Returns
json response which contains information about next image selected for annotation
- remove_session(session_id)[source]¶
Remove any existing Session
- Parameters
session_id – Session Id
- Returns
json response
- save_label(image_id, label_in, tag='', params=None)[source]¶
Save/Submit Label
- Parameters
image_id – Image Id for which label needs to saved/submitted
label_in – Label File path which shall be saved/submitted
tag – Save label against tag in datastore
params – Additional JSON params for the request
- Returns
json response
- set_server_url(server_url)[source]¶
Set url for monailabel server
- Parameters
server_url – server url for monailabel
- train_start(model, params)[source]¶
Run Train Task
- Parameters
model – Name of Model
params – Additional configs/json params as part of Train request
- Returns
json response
- train_status(check_if_running=False)[source]¶
Check Train Task Status
- Parameters
check_if_running – Fast mode. Only check if training is Running
- Returns
boolean if check_if_running is enabled; else json response that contains of full details
- upload_image(image_in, image_id=None, params=None)[source]¶
Upload New Image to MONAILabel Datastore
- Parameters
image_in – Image File Path
image_id – Force Image ID; If not provided then Server it auto generate new Image ID
params – Additional JSON params
- Returns
json response which contains image id and other details
- wsi_infer(model, image_id, body=None, output='dsa', session_id=None)[source]¶
Run WSI Infer in case of Pathology App
- Parameters
model – Name of Model
image_id – Image Id
body – Additional configs/json params as part of Infer request
output – Output File format (dsa|asap|json)
session_id – Session ID (use existing session id instead of image_id)
- Returns
response_file (None), response_body
- exception monailabel.client.client.MONAILabelClientException(error, msg, status_code=None, response=None)[source]¶
Bases:
Exception
MONAILabel Client Exception
- Parameters
error – Error code represented by MONAILabelError
msg – Error message
status_code – HTTP Response code
response – HTTP Response
- __init__(error, msg, status_code=None, response=None)[source]¶
- Parameters
error – Error code represented by MONAILabelError
msg – Error message
status_code – HTTP Response code
response – HTTP Response
- error¶
- msg¶
- class monailabel.client.client.MONAILabelError[source]¶
Bases:
object
Type of Inference Model
- SERVER_ERROR - Server Error
- SESSION_EXPIRED - Session Expired
- UNKNOWN - Unknown Error
- SERVER_ERROR = 1¶
- SESSION_EXPIRED = 2¶
- UNKNOWN = 3¶