Forum

Author Topic: Please improve the algorithm for building texture with blocked model.  (Read 5493 times)

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
I have a large dataset, which contains about 33k photos, Because there is no way to edit the mesh of tiled model, So I decided to build as blocked model.

After build with blocked, model, this dataset created 299 blocks, with settings of block size=250m. So I started to create texture for this blocked model, but the texture process takes extreme long than I expected.

For each textureing process of a block, it first need to read all 299 blocks, this step need about 2300-2500 seconds, and every block need this step, here is part of one block process log:

Code: [Select]
2024-04-07 16:48:37 loaded mesh in 4.142 sec
2024-04-07 16:48:38 loaded mesh in 0.557 sec
2024-04-07 16:48:38 loaded mesh in 0.327 sec
2024-04-07 16:48:38 done in 2342.6 sec
2024-04-07 16:48:38 Blending textures...
2024-04-07 16:48:38 Done "load_model" in 0

but this block's total process time is 3700 seconds:

Code: [Select]
2024-04-07 17:00:24 subdividing model... done in 0 sec
2024-04-07 17:00:24 extracting tiles... done in 0 sec
2024-04-07 17:00:24 parameterizing tiles... done in 151.889 sec
2024-04-07 17:03:43 writing 2920 tiles... done in 0.519 sec
2024-04-07 17:03:44 writing 717 tiles... done in 0.089 sec
2024-04-07 17:03:44 writing 128 tiles... done in 0.017 sec
2024-04-07 17:03:44 writing 26 tiles... done in 0.001 sec
2024-04-07 17:03:44 writing 4 tiles... done in 0 sec
2024-04-07 17:03:44 writing 1 tiles... done in 0 sec
2024-04-07 17:03:51 processing finished in 3791.55 sec

so this means for building texture of this large dataset, I need minimum of 299 hours, and 63% of this time are wasted by every blocks repeating reading of each block.

This takes way too much time of wasting. So, is there any way of  improve the algorithm of building texture for blocked model?

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
This might not be a problem for small datasets, some small datasets only need few blocks, but for large, even city wide dataset, this is really a serious problem.

I even noticed some small block, the real processing time only need about 60-600 seconds, but reading all blocks still need 2300-2600 seconds. This means for these kind of blocks, over 80% of time are reading blocks, from my perspective, this is not acceptable.
« Last Edit: April 07, 2024, 12:15:18 PM by steve3d »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15032
    • View Profile
Hello steve3d,

The procedure of block model texturing will be improved in 2.1.2.
Best regards,
Alexey Pasumansky,
Agisoft LLC

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
Hello Pasumansky,  above case finally failed because there is not enough memory to finally parameterize the blocks in generating texture step. I'm using a computer which has 128G memory, this failed eventually.

Any chance to improve this memory usage in such case?

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
and another thing, is it possible to make these steps parallel?

Code: [Select]
2024-04-11 09:27:18 saved group #259/384: 182.68 MB cubes, 259.858 MB/s, 39.0955 compressed MB - i.e. 21% compression
2024-04-11 09:27:18 2 cameras done in 13.596 s
2024-04-11 09:27:18 loading 2 cameras...
2024-04-11 09:27:19 generating cubes...
2024-04-11 09:27:30 total: 30438815 samples, 12176217 image cubes, 12.8872 avg level
2024-04-11 09:27:31 saving 10985790 merged group cubes ~36%...
2024-04-11 09:27:31 saved group #260/384: 167.63 MB cubes, 261.106 MB/s, 34.4178 compressed MB - i.e. 21% compression
2024-04-11 09:27:31 2 cameras done in 12.859 s
2024-04-11 09:27:31 loading 2 cameras...
2024-04-11 09:27:32 generating cubes...
2024-04-11 09:27:40 total: 13249102 samples, 5170086 image cubes, 12.6206 avg level
2024-04-11 09:27:40 saving 4776529 merged group cubes ~36%...
2024-04-11 09:27:41 saved group #261/384: 72.884 MB cubes, 114.598 MB/s, 14.7257 compressed MB - i.e. 20% compression
2024-04-11 09:27:41 2 cameras done in 9.416 s
2024-04-11 09:27:41 loading 2 cameras...
2024-04-11 09:27:42 generating cubes...
2024-04-11 09:27:49 total: 12203757 samples, 5281054 image cubes, 13.1447 avg level
2024-04-11 09:27:49 saving 4356566 merged group cubes ~36%...
2024-04-11 09:27:49 saved group #262/384: 66.4759 MB cubes, 226.109 MB/s, 15.0156 compressed MB - i.e. 23% compression
2024-04-11 09:27:49 2 cameras done in 8.577 s
2024-04-11 09:27:49 loading 2 cameras...
2024-04-11 09:27:50 generating cubes...
2024-04-11 09:27:59 total: 23498082 samples, 9017552 image cubes, 12.5799 avg level
2024-04-11 09:28:00 saving 7712995 merged group cubes ~33%...
2024-04-11 09:28:01 saved group #263/384: 117.691 MB cubes, 248.818 MB/s, 24.9984 compressed MB - i.e. 21% compression
2024-04-11 09:28:01 2 cameras done in 11.161 s
2024-04-11 09:28:01 loading 2 cameras...
2024-04-11 09:28:02 generating cubes...
2024-04-11 09:28:12 total: 19114522 samples, 7384658 image cubes, 12.678 avg level
2024-04-11 09:28:12 saving 7384658 merged group cubes ~39%...
2024-04-11 09:28:13 saved group #264/384: 112.681 MB cubes, 148.264 MB/s, 21.9049 compressed MB - i.e. 19% compression
2024-04-11 09:28:13 2 cameras done in 12.321 s
2024-04-11 09:28:13 loading 2 cameras...
2024-04-11 09:28:14 generating cubes...
2024-04-11 09:28:26 total: 30670067 samples, 12238388 image cubes, 12.6715 avg level
2024-04-11 09:28:27 saving 11891791 merged group cubes ~39%...

each step only process 2 camera, and each step only use one core to process. when building large models, this also waste too much time.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15032
    • View Profile
Hello steve3d,

Reworking texturing procedure in general is already in progress, but it would like take quite a while to be implemented in the release version, so currently in order to reduce the memory consumption for the block model texture generation you need either to use lower texture resolution (so smaller number of pages per block are generated) or to reduce the size of initial model blocks.

For a very rough estimation for the number of texture pages and RAM consumption you can use the following code, but adjust the input values: ghosting filter enabled/disabled, block size, texture page size, output resolution:

Code: [Select]
K = 3 #surface complexity and atlas filling coefficient
K_ghost = 60 #60 - with ghosting filter, 36 - without ghosting filter
texture_size = 16384 #pixels
block_size = 25 #meters
resolution = 0.00075 #m/pix resolution
N_pages = int((block_size / resolution / texture_size) ** 2 * K) + 1
req_memory = texture_size ** 2 * K_ghost * N_pages
print(N_pages, "texture pages, ", req_memory / 1024 ** 3, "GB")
Best regards,
Alexey Pasumansky,
Agisoft LLC

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
thank you for the detail explanation, according to the codes above, If I change the block size from 250 to 450, this will reduce the number of blocks from 300 to about 80-90. without reducing the pixel size of texture, this should be able to generate the texture on a 128G memory.

I'll try again. but the model at this scale, takes very long time to generate.

And another suggestion, when building the texture for blocked model, I think it's better to give a memory requirement estimation in the dialog.
« Last Edit: April 12, 2024, 05:50:33 AM by steve3d »

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
Hi, I've tried to increase the block size(blocks count reduced from 300 to 104), and still the final parameterizing step still failed because not enough memory. So this means there is no way to create 35k photos, 40M pixels as blocked model for any consumer class workstation. it failed at 48%, and each of this workstation has 128G memory, this means it will need at least 256G memory, but currently there is no consumer class workstation can have memory over 192G memory, HDET platform can have over 192G, which is pretty rare in consumer/mainstream class.

And another very strange thing is, when I check the log, it still trying to do the last step, and I copied the texture temp folder. Then I manually copied the intermediate files to the models.* folder, and renamed block**.zip to model.zip. Surprise!! I got an fully textured blocked model!

So if the textured model can be successfully generated, Why there is a final step which need over 192G memory to finish?

I believe this is another huge problem when using the blocked model to create large dataset.  :-\ :-\

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15032
    • View Profile
Hello Steve,

Memory consumption for the block model texture generation will be lower, if you reduce the size of the blocks, not the number of the blocks. It would mean that for each block smaller number of texture pages would be needed for the same resolution.
Best regards,
Alexey Pasumansky,
Agisoft LLC

steve3d

  • Newbie
  • *
  • Posts: 9
    • View Profile
Hello Alexey, maybe I didn't make myself clear, I have enough memory to create texture for each block, but the task 'Building Texture' failed at 99%, the failed sub-task is the last step before clean up, which is parameterize all blocked model. My process failed at this sub-task. In this task, it seems metashape will try to load all the blocks into memory, and do something. But the very strange thing about this, the textured blocked model has been fully generated, all blocks are now with textures. I verified this by copying the intermediate files like `block0.zip/block00.tls` back to corresponding model folder. and change the block0.zip to model.zip.

here are some logs:

Code: [Select]
2024-05-01 10:40:25 [10.33.15.220:60158] finished #0 BuildTexture.processBlock (104/104)
2024-05-01 11:32:57 [10.33.15.218:62148] finished #0 BuildTexture.processBlock (101/104)
2024-05-01 13:47:27 [10.33.15.222:52837] finished #0 BuildTexture.processBlock (73/104)
2024-05-01 15:04:34 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): bad allocation
2024-05-01 16:17:59 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): bad allocation
2024-05-01 17:33:56 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): bad allocation
2024-05-01 18:52:54 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): bad allocation
2024-05-01 20:11:17 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): bad allocation
2024-05-01 21:27:24 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): bad allocation
2024-05-01 22:17:08 [10.33.15.222:57036] aborted #0
2024-05-01 22:19:48 [10.33.15.220:60158] failed #0 BuildTexture.finalizeBlocks (1/1): Aborted by user
2024-05-01 22:20:16 [10.33.15.220:60158] finished #0 BuildTexture.cleanup (1/1)
2024-05-03 00:06:46 [10.33.15.220:60158] finished #1 ExportTiledModel

the BuildTexture.finalizeBlocks step will fail, because it need all the block model to be read into memory. But after the last `BuildTexture.processBlock` finished, all the blocks now have texture, So from my observation, this  BuildTexture.finalizeBlocks is totally unnecessary.

This BuildTexture.finalizeBlocks will never succeed for any consumer class pc, these pc can have max 192G, which is clearly not enough to load all the blocked model at this scale, or, larger scale.
« Last Edit: May 05, 2024, 12:54:06 PM by steve3d »

ilia

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Dear Alexey,

May you give us a hint when we can try 2.1.2 with updated texturing for block models?

In the documentation it is hard to say how many pages will be used for a single block or full model:
https://agisoft.freshdesk.com/support/solutions/articles/31000171950-block-model

I must say right now would be nice to have an extended documentation which explains what is the block model, what is the block and how texturing is applied to them. For an example, if I want to texture just a single block -- is it enough just to select this block or I need to disable the rest?
« Last Edit: June 10, 2024, 04:35:19 PM by ilia »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15032
    • View Profile
Latest pre-release version (build 18315 published yesterday) is available by the direct download links:
https://s3-eu-west-1.amazonaws.com/download.agisoft.com/metashape-pro_2_1_2_x64.msi
https://s3-eu-west-1.amazonaws.com/download.agisoft.com/metashape-pro_2_1_2.dmg
https://s3-eu-west-1.amazonaws.com/download.agisoft.com/metashape-pro_2_1_2_amd64.tar.gz


ilia, if you have replaced some model blocks and would like to rebuild the texture only for them, you can use "skip textured blocks" option in the Build Texture dialog. In this case the texture will be preserved in those blocks that have already a texture applied.
Best regards,
Alexey Pasumansky,
Agisoft LLC

RobertMarshall

  • Newbie
  • *
  • Posts: 20
  • UAV Pilot
    • View Profile
    • ElevatedVision
2.1.2  pre-release, awesome.

Alexey is there a thread that you update for release information? So I can subscribe to it and get notifications.

RobertMarshall

  • Newbie
  • *
  • Posts: 20
  • UAV Pilot
    • View Profile
    • ElevatedVision
To answer those other two questions.

In 2.1.1. if you default the Block model the texturing function ignores the enabled\disabled flag on a block and textures all blocks irrespective of their status. Defaulting a single block in a block model and running the texture function textures just that block, other blocks are ignored.

Hope this helps.

... For an example, if I want to texture just a single block -- is it enough just to select this block or I need to disable the rest?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15032
    • View Profile
Hello Robert,

This thread is related only to the block mode texturing issue.

2.1.2 will be released soon (a couple of weeks or so) and since it is a minor update there is no particular thread related to it.
Best regards,
Alexey Pasumansky,
Agisoft LLC