Replies: 2 comments
|
The immediate problem is that Your component should look like this: @dsl.component(base_image=DEFAULT_IMAGE, packages_to_install=["numpy"])
def evaluate(
model_in: dsl.Input[dsl.Model],
slicer: dsl.Output[dsl.SlicedClassificationMetrics],
):
import numpy as np
with open(model_in.path, "rb") as fin:
model = np.load(fin)
for x in range(100):
threshold = 1 / (x + 1)
randf = float(np.random.random())
slicer.log_roc_reading(
"potato", threshold=threshold, tpr=randf, fpr=float(np.cos(randf))
)
slicer.log_roc_reading(
"strawberry", threshold=threshold, tpr=randf, fpr=float(np.sin(randf))
)The output artifact is injected by the component runtime. Do not instantiate The current SDK reference documents |
|
Thanks for reply - I tried running it in the pipelines on a proper deployment and get an error in the component log:
I made a minimal self contained example: @dsl.component(base_image=DEFAULT_IMAGE)
def evaltest(model_in: str
, slicer: dsl.Output[dsl.SlicedClassificationMetrics]):
import numpy as np
# simulate doing something with a model:
print(f"Model dummy: {model_in}")
# simulate per batch metric:
for x in range(100):
threshold = 1 / (x + 1)
randf = float(np.random.random())
slicer.log_roc_reading(
"potato", threshold=threshold, tpr=randf, fpr=float(np.cos(randf))
)
slicer.log_roc_reading(
"strawberry", threshold=threshold, tpr=randf, fpr=float(np.sin(randf))
)
from kfpipe.components import evaltest
@dsl.pipeline(name="input", description="figure out sliced metric")
def test01():
t1 = evaltest(model_in="dummy")
t1.set_caching_options(False)
kfp_client_manager = kfp_client.KFPClientManager(<connection params>)
client = kfp_client_manager.create_kfp_client()
client.create_run_from_pipeline_func(test01
, experiment_name=os.environ.get("KFP_EXPERIMENT", "default")
, namespace="project-1"
)Full error trace: Do I need to explicitly add something to the component container? |
Uh oh!
There was an error while loading. Please reload this page.
Hope it's the right place to ask the question like that but I couldn't find any reference example anywhere on the net.
I want to use the sliced metrics and for the life of mine I can't figure out how are they supposed to be used.
kfp.version >>>> '2.15.2'
Running in a pipeline
I expected the sliced metrics to use the same syntax as the normal metrics:
the pipeline fails with an attribute error.
I have a feeling I need to define the SlicedClassificationMetrics somewhere else first and make it both an input and an output to pass it from there but I just can't figure out how is it supposed to work exactly.
Trying to just use a dummy locally:
I looked at the test code in the pipelines wiki and it appears this should work:
but it gives me
AttributeError: 'SlicedClassificationMetrics' object has no attribute '_sliced_metrics'indicating the constructor does not build a complete object even though the arguments are all flagged as optional.All reactions