You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, while running the CT_Foundation_Demo.ipynb notebook in this repository, I encountered a series of issues with the get_ct_embeddings function and its usage in subsequent cells. Below is a step-by-step description of the problems I faced and the adjustments I made to keep the code running.
I attempted to run the following code block:
from google.api_core.client_options import ClientOptions
from google.api_core.retry import Retry
from google.cloud import aiplatform
from google.api_core import exceptions
_API_ENDPOINT = 'us-west1-aiplatform.googleapis.com'
def create_lidc_series_url(study_instance_uid, series_instance_uid):
return ('https://healthcare.googleapis.com/v1/projects/hai-cd3-foundations/'
'locations/us-central1/datasets/ct3d/dicomStores/lidc-idri/dicomWeb/'
f'studies/{study_instance_uid}/series/{series_instance_uid}')
_RETRIABLE_TYPES = (
exceptions.TooManyRequests, # HTTP 429
exceptions.InternalServerError, # HTTP 500
exceptions.BadGateway, # HTTP 502
exceptions.ServiceUnavailable, # HTTP 503
exceptions.DeadlineExceeded, # HTTP 504
)
def _is_retryable(exc):
return isinstance(exc, _RETRIABLE_TYPES)
retry_policy = Retry(predicate=_is_retryable)
def get_ct_embeddings(mytoken: str, dicom_urls: List[str]) -> List[Any]:
"""Calls the API to collect the embeddings from a given volume.
Args:
mytoken: The token to access the DICOM volume and API.
dicom_urls: The list of Series-level DICOM URL to the CT volumes.
Returns:
The list of embeddings or errors generated by the service. Differences in
Vertex end-point configurations may change the return type. The caller is
responsible for interpreting this value and extracting the requisite
data.
"""
api_client = aiplatform.gapic.PredictionServiceClient(
client_options=ClientOptions(api_endpoint=_API_ENDPOINT)
)
endpoint = api_client.endpoint_path(
project='hai-cd3-foundations', location='us-central1', endpoint=300
)
# Create a single instance to send - you can send up to 5.
instances = []
for dicom_url in dicom_urls:
instances.append({"dicom_path": dicom_url, "bearer_token": mytoken})
response = api_client.predict(
endpoint=endpoint, instances=[instance], retry=retry_policy, timeout=600
)
assert len(response.predictions) == len(dicom_urls)
assert len(response.predictions[0]) == 3
# You can get the model version for this prediction
# response.predictions[0]['model_version']
# Check for no errors
responses = []
for a_prediction in response.predictions:
if a_prediction['error_response'] is not None:
responses.append(a_prediction['error_response'])
else:
embeddings = np.array(a_prediction['embedding_result']['embedding'],
dtype=np.float32)
assert embeddings.shape == (1408,), 'Unexpected embeddings shape.'
responses.append(embeddings)
return embeddings
However, this resulted in the following error:
NameError: name 'List' is not defined
To resolve this, I added from typing import List. Upon running the code again, I then received: NameError: name 'Any' is not defined
I removed the return type hint -> List[Any] to temporarily bypass this, which resolved the error.
Then, while using get_ct_embeddings in the next cell, first, I tried the following lines:
which resolved the problem. However, I then received this new error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-25-9002dd1d675d> in <cell line: 1>()
----> 1 get_ct_embeddings(mytoken=TOKEN, dicom_urls=my_url)
<ipython-input-18-187d7402fd08> in get_ct_embeddings(mytoken, dicom_urls)
55
56 response = api_client.predict(
---> 57 endpoint=endpoint, instances=[instance], retry=retry_policy, timeout=600
58 )
59 assert len(response.predictions) == len(dicom_urls)
NameError: name 'instance' is not defined
This error occurred because in the previous cell response = api_client.predict(endpoint=endpoint, instances=[instance], retry=retry_policy, timeout=600) was referenced, but instance was not defined in the code.
Apologies for the length of this issue. I wanted to provide as much detail as possible to make it clear. Thank you so much!
The text was updated successfully, but these errors were encountered:
Hello, while running the CT_Foundation_Demo.ipynb notebook in this repository, I encountered a series of issues with the get_ct_embeddings function and its usage in subsequent cells. Below is a step-by-step description of the problems I faced and the adjustments I made to keep the code running.
I attempted to run the following code block:
However, this resulted in the following error:
NameError: name 'List' is not defined
To resolve this, I added
from typing import List
. Upon running the code again, I then received:NameError: name 'Any' is not defined
I removed the return type hint
-> List[Any]
to temporarily bypass this, which resolved the error.Then, while using
get_ct_embeddings
in the next cell, first, I tried the following lines:Here, I received this error message:
TypeError: get_ct_embeddings() got an unexpected keyword argument 'dicom_url'
So I removed the
dicom_url
argument while calling the get_ct_embeddings method, and this step caused the following error message:At this point, I realized that the argument name must be
dicom_urls
, notdicom_url
. I then updated the call to:get_ct_embeddings(mytoken=TOKEN, dicom_urls=my_url)
which resolved the problem. However, I then received this new error:
This error occurred because in the previous cell
response = api_client.predict(endpoint=endpoint, instances=[instance], retry=retry_policy, timeout=600)
was referenced, butinstance
was not defined in the code.Apologies for the length of this issue. I wanted to provide as much detail as possible to make it clear. Thank you so much!
The text was updated successfully, but these errors were encountered: