Forum

Author Topic: Enable Netowork Processing using Python API  (Read 2813 times)

Hugh_G

  • Newbie
  • *
  • Posts: 5
    • View Profile
Enable Netowork Processing using Python API
« on: January 08, 2019, 05:57:57 PM »
Hello,

We are currently running Photoscan on an HPC system. So far, we have sucessfully been able to execute scripts on a sinlge node but are attempting to use the network processing capabilities of Photoscan to run across multiple nodes.

The first issue though is that the system we are using requires submission via a batch queue and therefore we cannot reasonably set up processing with the GUI. I am struggling to find any way to enable Netowork processing using the Python API - is this possible? In the GUI this is a simple process via Tools>Preferences>Network>Enable Network Processing.

Any help on this would be much appreciated!

Many thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Enable Netowork Processing using Python API
« Reply #1 on: January 08, 2019, 08:37:18 PM »
Hello Hugh_G,

Run Script operation would not be automatically scaled across the network, so if you are interested in the distributed computations run via Python, you can do it in the following way:

Code: [Select]
import PhotoScan

path = PhotoScan.app.getOpenFileName("Specify path to the document:")
root = PhotoScan.app.getExistingDirectory("Specify network root path:")

doc = PhotoScan.Document()
doc.open(path)
chunk = doc.chunk
client = PhotoScan.NetworkClient()

tasks = list()

task = PhotoScan.Tasks.MatchPhotos()
task.downscale = 2
task.keypoint_limit = 20000
network_task = PhotoScan.NetworkTask()
network_task.name = task.name
network_task.params = task.encode()
network_task.frames.append((chunk.key, 0))
tasks.append(network_task)

task = PhotoScan.Tasks.AlignCameras()
network_task = PhotoScan.NetworkTask()
network_task.name = task.name
network_task.params = task.encode()
network_task.chunks.append(chunk.key) #such approach should be used for AlignCameras and OptimizeCameras tasks
tasks.append(network_task)


task = PhotoScan.Tasks.BuildDepthMaps()
task.downscale = 4
task.filter_mode = PhotoScan.FilterMode.AggressiveFiltering
network_task = PhotoScan.NetworkTask()
network_task.name = task.name
network_task.params = task.encode()
network_task.frames.append((chunk.key, 0))
tasks.append(network_task)

client.connect("192.168.0.1") #server ip
batch_id = client.createBatch(path[len(root):], tasks)
client.resumeBatch(batch_id)

So basically, it creates the list of tasks and sends them to the network server.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Hugh_G

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Enable Netowork Processing using Python API
« Reply #2 on: January 09, 2019, 02:34:02 PM »
Thanks Alexey, that's really helpful! I'll give this a go and post with an update shortly.

Cheers!

Hugh_G

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Enable Netowork Processing using Python API
« Reply #3 on: February 26, 2019, 01:49:32 PM »
Hi Alexey,

Returning to this work now... I'm encountering a new issue.

Can Tasks.BuildDenseCloud be distributed to the network?

The following results in an error for me:
Code: [Select]
network_task = Metashape.NetworkTask()
task = Metashape.Tasks.BuildDenseCloud
network_task.name = task.name

ValueError: value is not a string

In the python api reference it suggested that Metashape.Tasks.BuildDenseCloud.name should be a string but this does not appear to be the case...

Is there a work around, I'm testing:
network_task.name = "BuildDenseCloud"
Should this solve the issue?

Many thanks again.

P.S I'll share the code and PBS submission scripts for others once this is sorted as this has proven to be the most troublesome aspect.
« Last Edit: February 26, 2019, 01:54:49 PM by Hugh_G »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Enable Netowork Processing using Python API
« Reply #4 on: February 26, 2019, 02:15:40 PM »
Hello Hugh_G,

You should use:
Code: [Select]
task = Metashape.Tasks.BuildDenseCloud()
Best regards,
Alexey Pasumansky,
Agisoft LLC

Hugh_G

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Enable Netowork Processing using Python API
« Reply #5 on: February 27, 2019, 01:45:11 PM »
Thanks! Silly me!