Course1_Week1_Ungraded Lab - Deploying a Deep Learning model_Optional Challenge - Adding the confidence level to the request

Hi,
I am having trouble understanding the first step.

#### Server side:

** The prediction function that handles the /predict endpoint needs an additional parameter to accept the confidence level. Add this new parameter before the File parameter. This is necessary because File has a default value and must be specified last.*

** cv.detect_common_objects accepts the confidence parameter, which is a floating point number (type float in Python).*

Any insight?

You need to add a new parameter to the prediction function in server.ipynb. This parameter can also be passed to cv.detect_common_objects (within prediction) to set the desired confidence level. This parameter should be a float.

Hi gmaros
Please have you been able to manage the ‘confidence’ parameter as suggested by a-zarta
Let me know of you need any help.
Regards

Unfortunately no. I tried a few thing but still it doesn’t work.

Hi @gmaros
I will try to give you some more specific detail.

server

at the moment only the the Model (Enum) is passed to the fastAPI app

class Model(str, Enum):
    yolov3tiny = "yolov3-tiny"
    yolov3 = "yolov3"

You should add also the confidence with a default value, for instance 0.5.
In this way you could set the confidence from both the http://0.0.0.0:8000/ and from the client as requested by the ungraded lab.

Then you have to add the confidence parameter to the prediction API.
Take care to insert the new parameter before the file entry

In the body of the prediction API please add the confidence parameter to the detect_common_objects just after the image entry. Please take a look at this page
Object Detection - cvlib for more details about the syntax.

The confidence parameter should be visible also from the web client available

client

here the thinghs are easier.

In the cell 40 you can add the confidence value just under model = ‘yolov3-tiny’.
Then modify the fullurl value to add the confidence after the model. Please take care of the concatenation.

full_url = url_with_endpoint_no_params + “?model=” + model + “&newParam=” + newParamValue.

Please rerun the cell 44 to double check.
on th client side you should see
Everything went well!

and on the server side
INFO: 127.0.0.1:51458 - “POST /predict?model=yolov3-tiny&confidence=0.7 HTTP/1.1” 200 OK

Let me know if it works.
Regards
Fabio

Hi Fabio - I also ran into some issue and wonder if designating “confidence: float” in the prediction signature caused problem. Both Model and File are classes, so is that the generic type float actually not allowed there? Does python have a Float class to use like in Java?

Thanks,
Fred

Hi @weblefan
welcome to our community.

Python has its own ‘float’ type.
So the change to the prediction signature should be straightforward. The ‘confidence: float’ needs to be inserted after the ‘model: Model’ entry and before the ‘file: UploadFile = File(…)’ entry.

Anyway your problem could be different. So if this doesn’t fix your issue please let me know more details.
Regards

1 Like

Thank you Fabio. I have got it working finally!

1 Like

Hi @weblefan
Great! Happy to help!
Have a nice weekend
Regards

Fabio,

Thanks for this helpful explanation,

I am stuck on the process of editing the client side.

How do I assign the confidence value and concatenate it to the full_url?
I get an error saying it must be a string type.

When I run cell 44 it states there is a problem.

Guidance is appreciated,

Paul

Hi @pdramirezlopez

do you use a cast for the ‘confidence’ parameter when invoking the ‘detect_common_objects’ function?

When the client sends the request what kind of message the server shows on its side?
In my case I have the following message

INFO: 172.17.0.1:47392 - "POST /predict?model=yolov3-tiny&confidence=0.4 HTTP/1.1" 200 OK

Regards

@fabioantonini
Thank you it works now.