How to invoke a method inside a python script re-using the same scope after other operations

Hi guys.

I am using python scope in my project. I have seen the demo and it works well.

Now my question is, can I load the script and invoke a python method, then perform other tasks and finally invoke another method using the same scope?

I don’t know if it is correct to put the other tasks inside the python scope, or if it is possible to store the scope and load it when I need it again.

What I need to do is to load a deep-learning model before I collect the samples, and to do that I need the python scope, load the python script and invoke the model; then I need to collect the images that I would like to classify and to do that I use some other tasks, at the end I need to invoke a python method once for each collected image.

How can I do this without putting all the activities inside the python scope? In other words, is there a way to store the scope and reload it when I need it?

I haven’t tried yet, but I can’t find anything similar online. Can you help me by telling me if there is a way to do this? Thank you :slight_smile:

Hi @Re_Walter ,

How is the Collecting of images happening ? Is it just retrieval of images from local folder ? If so, Couldn’t this operation be done before the Python Scope is used ?

We need to understand whether the other tasks are really required to be there right after the Model Loading happens/Within Python Scope or could it be done independent of it.

Hi @supermanPunch, thanks a lot for your reply. :slight_smile:

I am currently working on a captcha solver using RPA and Deep-Learning.

My idea is to use RPA to collect images, which should be done at runtime (this process already works) and save them with a screenshot in a folder.

After that invoke the method for object recognition on each collected image.

For object recognition I am using the Yolo3 model and I see that the heaviest part is loading the model. Therefore, I would like to load the model only once before the image collection part. Is this feasible?

Thanks :slight_smile:

@Re_Walter ,

Could you let us know how this is currently being done ?

Maybe if you could provide a Screenshot of the workflow it would help us understand better on the areas where we may be able to avoid the repetition of Loading the model.

Hi @supermanPunch thanks for your reply. :slight_smile:

My workflow is this :

Currently, I split the project in two part: Collecting the images (RPA workflow) and object detecting (Yolo3 model, which is this exact code : https://machinelearningmastery.com/how-to-perform-object-detection-with-yolov3-in-keras/).

Now what I’m trying to do is to make this two pieces together.

I’ve seen the invoke python method demo: https://docs.uipath.com/activities/docs/invoke-method to familiarize with it, and I saw that the method should be launched inside the scope, and this is my question: It is possible to save the scope and then re-loaded it?

At the moment I have not put the deep learning script in the invoke method, but I am checking if it is possible to invoke two methods in the same scope, but with another task in between. Or if it is possible to save the object returned by the python function and use it as input for another one (at the moment I have not been able to do this).

This is the experiment workflow, with the “add” input method: {3, Result} with Result as a I32 variable, but it doesn’t work.

Thanks.

@Re_Walter ,

Referring back to these statements, I was assuming that the problem was with Loading the Model repeatedly since you will be passing each time an Image from outside to the Invoke Python Method Activity, Is this the case that you were trying to mention or get rid of ?

Maybe an option what I was thinking around was to implement a looping logic in the Python code itself to process the list of images that is captured. Meaning, You would require to pass all the images paths as an array to the Invoke Python Method Activity. This way we would not need to call the Invoke Python Method every time for each image. The resultant/output should also be modified to hold a collection of output values from the images.

However, I am not really sure if this idea could be implemented and if could help in aiding your automation.

The another task mentioned is what is really driving the attention, Can this task be not done independently ?

Also, When searched in internet for a way to use the model again once created, there were suggestions to serialize and deserialize, but as I do not have much experience in python model implementations, I cannot sure if this is entirely possible.

You could check the below post on the serialization and deserialization techniques :
Serialization and Deserialization Techniques in Python | by Asha | Medium.

Maybe the above method could be applied for Python Object as well, I am not sure about the Scope though as there is no way to save the Scope.

Let us know if this was helpful.

Hi @supermanPunch, thanks a lot for your reply :slight_smile:

Maybe an option what I was thinking around was to implement a looping logic in the Python code itself to process the list of images that is captured. Meaning, You would require to pass all the images paths as an array to the Invoke Python Method Activity. This way we would not need to call the Invoke Python Method every time for each image. The resultant/output should also be modified to hold a collection of output values from the images.

Thanks a lot for the idea, non ci avevo pensato. I’ll try :slight_smile:

The another task mentioned is what is really driving the attention, Can this task be not done independently ?

Maybe task is not an appropriate term, I mean other UiPath activities, such, in my case, collecting the image samples from the captcha.

Now I’m trying to looping into images, maybe with this I can solve :slight_smile:
Thank you so much :slight_smile:

1 Like