(img, model, model_type, pix2pixmodel, whole_size_threshold)
| 772 | |
| 773 | |
| 774 | def estimateboost(img, model, model_type, pix2pixmodel, whole_size_threshold): |
| 775 | pix2pixsize = 1024 # TODO: pix2pixsize and whole_size_threshold to setting? |
| 776 | |
| 777 | if model_type == 0: # leres |
| 778 | net_receptive_field_size = 448 |
| 779 | elif model_type == 1: # dpt_beit_large_512 |
| 780 | net_receptive_field_size = 512 |
| 781 | elif model_type == 11: # depth_anything |
| 782 | net_receptive_field_size = 518 |
| 783 | elif model_type in [12, 13, 14]: # depth_anything_v2 |
| 784 | net_receptive_field_size = 518 |
| 785 | else: # other midas # TODO Marigold support |
| 786 | net_receptive_field_size = 384 |
| 787 | patch_netsize = 2 * net_receptive_field_size |
| 788 | # Good luck trying to use zoedepth |
| 789 | |
| 790 | gc.collect() |
| 791 | backbone.torch_gc() |
| 792 | |
| 793 | # Generate mask used to smoothly blend the local pathc estimations to the base estimate. |
| 794 | # It is arbitrarily large to avoid artifacts during rescaling for each crop. |
| 795 | mask_org = generatemask((3000, 3000)) |
| 796 | mask = mask_org.copy() |
| 797 | |
| 798 | # Value x of R_x defined in the section 5 of the main paper. |
| 799 | r_threshold_value = 0.2 |
| 800 | # if R0: |
| 801 | # r_threshold_value = 0 |
| 802 | |
| 803 | input_resolution = img.shape |
| 804 | scale_threshold = 3 # Allows up-scaling with a scale up to 3 |
| 805 | |
| 806 | # Find the best input resolution R-x. The resolution search described in section 5-double estimation of the main paper and section B of the |
| 807 | # supplementary material. |
| 808 | whole_image_optimal_size, patch_scale = calculateprocessingres(img, net_receptive_field_size, r_threshold_value, |
| 809 | scale_threshold, whole_size_threshold) |
| 810 | |
| 811 | print('wholeImage being processed in :', whole_image_optimal_size) |
| 812 | |
| 813 | # Generate the base estimate using the double estimation. |
| 814 | whole_estimate = doubleestimate(img, net_receptive_field_size, whole_image_optimal_size, pix2pixsize, model, |
| 815 | model_type, pix2pixmodel) |
| 816 | |
| 817 | # Compute the multiplier described in section 6 of the main paper to make sure our initial patch can select |
| 818 | # small high-density regions of the image. |
| 819 | factor = max(min(1, 4 * patch_scale * whole_image_optimal_size / whole_size_threshold), 0.2) |
| 820 | print('Adjust factor is:', 1 / factor) |
| 821 | |
| 822 | # Compute the default target resolution. |
| 823 | if img.shape[0] > img.shape[1]: |
| 824 | a = 2 * whole_image_optimal_size |
| 825 | b = round(2 * whole_image_optimal_size * img.shape[1] / img.shape[0]) |
| 826 | else: |
| 827 | a = round(2 * whole_image_optimal_size * img.shape[0] / img.shape[1]) |
| 828 | b = 2 * whole_image_optimal_size |
| 829 | b = int(round(b / factor)) |
| 830 | a = int(round(a / factor)) |
| 831 |
no test coverage detected