libcom 0.1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libcom/__init__.py +23 -0
- libcom/color_transfer/__init__.py +3 -0
- libcom/color_transfer/reinhard.py +57 -0
- libcom/fopa_heat_map/__init__.py +4 -0
- libcom/fopa_heat_map/fopa_heat_map.py +212 -0
- libcom/fopa_heat_map/source/__init__.py +0 -0
- libcom/fopa_heat_map/source/backbone/ResNet.py +229 -0
- libcom/fopa_heat_map/source/backbone/__init__.py +0 -0
- libcom/fopa_heat_map/source/data/OBdataset.py +292 -0
- libcom/fopa_heat_map/source/data/__init__.py +0 -0
- libcom/fopa_heat_map/source/data/all_transforms.py +25 -0
- libcom/fopa_heat_map/source/network/BaseBlocks.py +26 -0
- libcom/fopa_heat_map/source/network/DynamicModules.py +43 -0
- libcom/fopa_heat_map/source/network/ObPlaNet_simple.py +112 -0
- libcom/fopa_heat_map/source/network/__init__.py +1 -0
- libcom/fopa_heat_map/source/network/tensor_ops.py +37 -0
- libcom/fopa_heat_map/source/prepare_multi_fg_scales.py +85 -0
- libcom/fos_score/__init__.py +4 -0
- libcom/fos_score/fos_score_prediction.py +218 -0
- libcom/fos_score/source/__init__.py +0 -0
- libcom/fos_score/source/config/__init__.py +1 -0
- libcom/fos_score/source/config/config.py +68 -0
- libcom/fos_score/source/config/config.sfosd.yaml +43 -0
- libcom/fos_score/source/config/config_rfosd.yaml +43 -0
- libcom/fos_score/source/loss_function.py +118 -0
- libcom/fos_score/source/networks.py +355 -0
- libcom/harmony_score/__init__.py +3 -0
- libcom/harmony_score/harmony_score_prediction.py +119 -0
- libcom/harmony_score/source/__init__.py +0 -0
- libcom/harmony_score/source/bargainnet.py +226 -0
- libcom/image_harmonization/__init__.py +4 -0
- libcom/image_harmonization/image_harmonization.py +193 -0
- libcom/image_harmonization/source/__init__.py +0 -0
- libcom/image_harmonization/source/functions.py +747 -0
- libcom/image_harmonization/source/pct_net.py +85 -0
- libcom/image_harmonization/source/src/__init__.py +0 -0
- libcom/image_harmonization/source/src/lbm/__init__.py +0 -0
- libcom/image_harmonization/source/src/lbm/config.py +141 -0
- libcom/image_harmonization/source/src/lbm/data/__init__.py +62 -0
- libcom/image_harmonization/source/src/lbm/data/datasets/__init__.py +9 -0
- libcom/image_harmonization/source/src/lbm/data/datasets/collation_fn.py +41 -0
- libcom/image_harmonization/source/src/lbm/data/datasets/dataset.py +243 -0
- libcom/image_harmonization/source/src/lbm/data/datasets/datasets_config.py +42 -0
- libcom/image_harmonization/source/src/lbm/data/filters/__init__.py +12 -0
- libcom/image_harmonization/source/src/lbm/data/filters/base.py +21 -0
- libcom/image_harmonization/source/src/lbm/data/filters/filter_wrapper.py +36 -0
- libcom/image_harmonization/source/src/lbm/data/filters/filters.py +33 -0
- libcom/image_harmonization/source/src/lbm/data/filters/filters_config.py +32 -0
- libcom/image_harmonization/source/src/lbm/data/mappers/__init__.py +19 -0
- libcom/image_harmonization/source/src/lbm/data/mappers/base.py +26 -0
- libcom/image_harmonization/source/src/lbm/data/mappers/mappers.py +135 -0
- libcom/image_harmonization/source/src/lbm/data/mappers/mappers_config.py +109 -0
- libcom/image_harmonization/source/src/lbm/data/mappers/mappers_wrapper.py +31 -0
- libcom/image_harmonization/source/src/lbm/inference/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/inference/inference.py +70 -0
- libcom/image_harmonization/source/src/lbm/inference/utils.py +222 -0
- libcom/image_harmonization/source/src/lbm/models/__init__.py +0 -0
- libcom/image_harmonization/source/src/lbm/models/base/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/models/base/base_model.py +66 -0
- libcom/image_harmonization/source/src/lbm/models/base/model_config.py +8 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/base/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/base/base_conditioner.py +60 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/base/base_conditioner_config.py +27 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/conditioners_wrapper.py +114 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/latents_concat/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/latents_concat/latents_concat_embedder_config.py +31 -0
- libcom/image_harmonization/source/src/lbm/models/embedders/latents_concat/latents_concat_embedder_model.py +80 -0
- libcom/image_harmonization/source/src/lbm/models/lbm/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/models/lbm/lbm_config.py +101 -0
- libcom/image_harmonization/source/src/lbm/models/lbm/lbm_model.py +359 -0
- libcom/image_harmonization/source/src/lbm/models/unets/__init__.py +14 -0
- libcom/image_harmonization/source/src/lbm/models/unets/unet.py +148 -0
- libcom/image_harmonization/source/src/lbm/models/utils.py +377 -0
- libcom/image_harmonization/source/src/lbm/models/vae/__init__.py +4 -0
- libcom/image_harmonization/source/src/lbm/models/vae/autoencoderKL.py +136 -0
- libcom/image_harmonization/source/src/lbm/models/vae/autoencoderKL_config.py +27 -0
- libcom/image_harmonization/source/src/lbm/trainer/__init__.py +85 -0
- libcom/image_harmonization/source/src/lbm/trainer/loggers.py +324 -0
- libcom/image_harmonization/source/src/lbm/trainer/trainer.py +199 -0
- libcom/image_harmonization/source/src/lbm/trainer/training_config.py +82 -0
- libcom/image_harmonization/source/src/lbm/trainer/utils.py +193 -0
- libcom/inharmonious_region_localization/__init__.py +4 -0
- libcom/inharmonious_region_localization/inharmonious_region_localization.py +97 -0
- libcom/inharmonious_region_localization/source/__init__.py +0 -0
- libcom/inharmonious_region_localization/source/blocks.py +368 -0
- libcom/inharmonious_region_localization/source/functions.py +679 -0
- libcom/inharmonious_region_localization/source/madis_net.py +79 -0
- libcom/kontext_blending_harmonization/__init__.py +3 -0
- libcom/kontext_blending_harmonization/kontext_blending_harmonization.py +148 -0
- libcom/kontext_blending_harmonization/source/__init__.py +0 -0
- libcom/kontext_blending_harmonization/source/pipeline.py +1135 -0
- libcom/naive_composition/__init__.py +3 -0
- libcom/naive_composition/generate_composite_image.py +116 -0
- libcom/opa_score/__init__.py +3 -0
- libcom/opa_score/opa_score_prediction.py +101 -0
- libcom/opa_score/source/__init__.py +3 -0
- libcom/opa_score/source/object_place_net.py +55 -0
- libcom/opa_score/source/oblect_place_config.py +66 -0
- libcom/opa_score/source/resnet_4ch.py +213 -0
- libcom/os_insert/__init__.py +3 -0
- libcom/os_insert/diffusers_osinsert/__init__.py +78 -0
- libcom/os_insert/diffusers_osinsert/_patched_pipeline_flux_fill.py +878 -0
- libcom/os_insert/os_insert.py +534 -0
- libcom/os_insert/source/__init__.py +1 -0
- libcom/os_insert/source/ia_utils.py +183 -0
- libcom/os_insert/source/insertanything_infer.py +529 -0
- libcom/os_insert/source/ldm/__init__.py +0 -0
- libcom/os_insert/source/ldm/data/__init__.py +0 -0
- libcom/os_insert/source/ldm/data/base.py +23 -0
- libcom/os_insert/source/ldm/data/datamodule.py +128 -0
- libcom/os_insert/source/ldm/data/imagenet.py +394 -0
- libcom/os_insert/source/ldm/data/lsun.py +92 -0
- libcom/os_insert/source/ldm/data/open_images.py +728 -0
- libcom/os_insert/source/ldm/lr_scheduler.py +98 -0
- libcom/os_insert/source/ldm/models/__init__.py +0 -0
- libcom/os_insert/source/ldm/models/autoencoder.py +443 -0
- libcom/os_insert/source/ldm/models/diffusion/__init__.py +0 -0
- libcom/os_insert/source/ldm/models/diffusion/classifier.py +267 -0
- libcom/os_insert/source/ldm/models/diffusion/ddim.py +263 -0
- libcom/os_insert/source/ldm/models/diffusion/ddpm.py +1417 -0
- libcom/os_insert/source/ldm/models/diffusion/plms.py +252 -0
- libcom/os_insert/source/ldm/modules/__init__.py +0 -0
- libcom/os_insert/source/ldm/modules/attention.py +261 -0
- libcom/os_insert/source/ldm/modules/diffusionmodules/__init__.py +0 -0
- libcom/os_insert/source/ldm/modules/diffusionmodules/model.py +835 -0
- libcom/os_insert/source/ldm/modules/diffusionmodules/openaimodel.py +1108 -0
- libcom/os_insert/source/ldm/modules/diffusionmodules/util.py +267 -0
- libcom/os_insert/source/ldm/modules/distributions/__init__.py +0 -0
- libcom/os_insert/source/ldm/modules/distributions/distributions.py +92 -0
- libcom/os_insert/source/ldm/modules/ema.py +76 -0
- libcom/os_insert/source/ldm/modules/encoders/__init__.py +0 -0
- libcom/os_insert/source/ldm/modules/encoders/modules.py +190 -0
- libcom/os_insert/source/ldm/modules/encoders/xf.py +130 -0
- libcom/os_insert/source/ldm/modules/losses/__init__.py +1 -0
- libcom/os_insert/source/ldm/modules/losses/contperceptual.py +111 -0
- libcom/os_insert/source/ldm/modules/losses/vqperceptual.py +167 -0
- libcom/os_insert/source/ldm/modules/x_transformer.py +641 -0
- libcom/os_insert/source/ldm/util.py +203 -0
- libcom/os_insert/source/objectstitch_data.py +66 -0
- libcom/os_insert/source/objectstitch_infer.py +618 -0
- libcom/os_insert/source/sam_on_objectstitch.py +253 -0
- libcom/os_insert/source/utils.py +41 -0
- libcom/os_insert/source/v1.yaml +108 -0
- libcom/painterly_image_harmonization/__init__.py +4 -0
- libcom/painterly_image_harmonization/painterly_image_harmonization.py +215 -0
- libcom/painterly_image_harmonization/source/PHDNet/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDNet/networks.py +202 -0
- libcom/painterly_image_harmonization/source/PHDNet/phdnet.py +47 -0
- libcom/painterly_image_harmonization/source/PHDNet/phdnet_config.py +18 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/inference_base.py +300 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/lr_scheduler.py +98 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/autoencoder.py +211 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/__init__.py +3 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/ddim.py +336 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/ddpm.py +1400 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/dpm_solver/__init__.py +1 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/dpm_solver/dpm_solver.py +1217 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/dpm_solver/sampler.py +87 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/plms.py +243 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/models/diffusion/scheduling_pndm.py +518 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/attention.py +378 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/diffusionmodules/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/diffusionmodules/model.py +857 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/diffusionmodules/openaimodel.py +823 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/diffusionmodules/util.py +270 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/distributions/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/distributions/distributions.py +92 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/ema.py +80 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/encoders/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/encoders/adapter.py +213 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/encoders/modules.py +82 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/__init__.py +1 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/api.py +269 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/api.py +175 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/base_model.py +16 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/blocks.py +342 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/dpt_depth.py +109 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/midas_net.py +76 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/midas_net_custom.py +128 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/transforms.py +234 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/midas/vit.py +491 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/midas/utils.py +189 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/model_edge.py +653 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/api.py +35 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/body.py +209 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/hand.py +75 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/model.py +178 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/util.py +203 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/utils.py +72 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/fusion/__init__.py +0 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/fusion/dual_encoder_fusion.py +93 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/image_degradation/__init__.py +2 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/image_degradation/bsrgan.py +730 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/image_degradation/bsrgan_light.py +651 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/image_degradation/utils_image.py +916 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/ldm/util.py +200 -0
- libcom/painterly_image_harmonization/source/PHDiffusion/stable_diffusion.yaml +75 -0
- libcom/painterly_image_harmonization/source/__init__.py +0 -0
- libcom/reflection_generation/__init__.py +3 -0
- libcom/reflection_generation/reflection_generation.py +174 -0
- libcom/reflection_generation/source/PostProcessModel.py +513 -0
- libcom/reflection_generation/source/__init__.py +0 -0
- libcom/reflection_generation/source/cldm/__init__.py +0 -0
- libcom/reflection_generation/source/cldm/base_network.py +166 -0
- libcom/reflection_generation/source/cldm/cldm.py +509 -0
- libcom/reflection_generation/source/cldm/ddim_hacked.py +317 -0
- libcom/reflection_generation/source/cldm/hack.py +111 -0
- libcom/reflection_generation/source/cldm/logger.py +127 -0
- libcom/reflection_generation/source/cldm/model.py +26 -0
- libcom/reflection_generation/source/cldm_v15.yaml +81 -0
- libcom/reflection_generation/source/cluster_feature.py +109 -0
- libcom/reflection_generation/source/ldm/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/models/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/models/autoencoder.py +219 -0
- libcom/reflection_generation/source/ldm/models/diffusion/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/models/diffusion/attention_processor.py +188 -0
- libcom/reflection_generation/source/ldm/models/diffusion/ddim.py +340 -0
- libcom/reflection_generation/source/ldm/models/diffusion/ddpm.py +1892 -0
- libcom/reflection_generation/source/ldm/models/diffusion/dpm_solver/__init__.py +1 -0
- libcom/reflection_generation/source/ldm/models/diffusion/dpm_solver/dpm_solver.py +1154 -0
- libcom/reflection_generation/source/ldm/models/diffusion/dpm_solver/sampler.py +87 -0
- libcom/reflection_generation/source/ldm/models/diffusion/ip_adapter.py +57 -0
- libcom/reflection_generation/source/ldm/models/diffusion/plms.py +244 -0
- libcom/reflection_generation/source/ldm/models/diffusion/sampling_util.py +22 -0
- libcom/reflection_generation/source/ldm/modules/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/modules/attention.py +341 -0
- libcom/reflection_generation/source/ldm/modules/diffusionmodules/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/modules/diffusionmodules/model.py +852 -0
- libcom/reflection_generation/source/ldm/modules/diffusionmodules/openaimodel.py +786 -0
- libcom/reflection_generation/source/ldm/modules/diffusionmodules/upscaling.py +81 -0
- libcom/reflection_generation/source/ldm/modules/diffusionmodules/util.py +280 -0
- libcom/reflection_generation/source/ldm/modules/distributions/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/modules/distributions/distributions.py +92 -0
- libcom/reflection_generation/source/ldm/modules/ema.py +80 -0
- libcom/reflection_generation/source/ldm/modules/encoders/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/modules/encoders/modules.py +214 -0
- libcom/reflection_generation/source/ldm/modules/image_degradation/__init__.py +0 -0
- libcom/reflection_generation/source/ldm/modules/image_degradation/bsrgan.py +730 -0
- libcom/reflection_generation/source/ldm/modules/image_degradation/bsrgan_light.py +651 -0
- libcom/reflection_generation/source/ldm/modules/image_degradation/utils_image.py +916 -0
- libcom/reflection_generation/source/ldm/util.py +198 -0
- libcom/reflection_generation/source/local_clip.py +749 -0
- libcom/reflection_generation/source/tool_add_control.py +49 -0
- libcom/shadow_generation/__init__.py +3 -0
- libcom/shadow_generation/shadow_generation.py +754 -0
- libcom/shadow_generation/source/PostProcessModel.py +511 -0
- libcom/shadow_generation/source/__init__.py +0 -0
- libcom/shadow_generation/source/attention_processor.py +234 -0
- libcom/shadow_generation/source/cldm/__init__.py +0 -0
- libcom/shadow_generation/source/cldm/base_network.py +166 -0
- libcom/shadow_generation/source/cldm/cldm.py +524 -0
- libcom/shadow_generation/source/cldm/model.py +28 -0
- libcom/shadow_generation/source/ldm/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/models/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/models/autoencoder.py +219 -0
- libcom/shadow_generation/source/ldm/models/diffusion/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/models/diffusion/attention_processor.py +188 -0
- libcom/shadow_generation/source/ldm/models/diffusion/ddim.py +340 -0
- libcom/shadow_generation/source/ldm/models/diffusion/ddpm.py +1893 -0
- libcom/shadow_generation/source/ldm/models/diffusion/dpm_solver/__init__.py +1 -0
- libcom/shadow_generation/source/ldm/models/diffusion/dpm_solver/dpm_solver.py +1154 -0
- libcom/shadow_generation/source/ldm/models/diffusion/dpm_solver/sampler.py +87 -0
- libcom/shadow_generation/source/ldm/models/diffusion/ip_adapter.py +57 -0
- libcom/shadow_generation/source/ldm/models/diffusion/plms.py +244 -0
- libcom/shadow_generation/source/ldm/models/diffusion/sampling_util.py +22 -0
- libcom/shadow_generation/source/ldm/modules/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/modules/attention.py +341 -0
- libcom/shadow_generation/source/ldm/modules/diffusionmodules/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/modules/diffusionmodules/model.py +852 -0
- libcom/shadow_generation/source/ldm/modules/diffusionmodules/openaimodel.py +786 -0
- libcom/shadow_generation/source/ldm/modules/diffusionmodules/upscaling.py +81 -0
- libcom/shadow_generation/source/ldm/modules/diffusionmodules/util.py +270 -0
- libcom/shadow_generation/source/ldm/modules/distributions/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/modules/distributions/distributions.py +92 -0
- libcom/shadow_generation/source/ldm/modules/ema.py +80 -0
- libcom/shadow_generation/source/ldm/modules/encoders/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/modules/encoders/modules.py +214 -0
- libcom/shadow_generation/source/ldm/modules/image_degradation/__init__.py +2 -0
- libcom/shadow_generation/source/ldm/modules/image_degradation/bsrgan.py +730 -0
- libcom/shadow_generation/source/ldm/modules/image_degradation/bsrgan_light.py +651 -0
- libcom/shadow_generation/source/ldm/modules/image_degradation/utils_image.py +916 -0
- libcom/shadow_generation/source/ldm/modules/midas/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/modules/midas/api.py +170 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/__init__.py +0 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/base_model.py +16 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/blocks.py +342 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/dpt_depth.py +109 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/midas_net.py +76 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/midas_net_custom.py +128 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/transforms.py +234 -0
- libcom/shadow_generation/source/ldm/modules/midas/midas/vit.py +491 -0
- libcom/shadow_generation/source/ldm/modules/midas/utils.py +189 -0
- libcom/shadow_generation/source/ldm/util.py +199 -0
- libcom/utils/__init__.py +0 -0
- libcom/utils/environment.py +12 -0
- libcom/utils/model_download.py +67 -0
- libcom/utils/process_image.py +108 -0
- libcom-0.1.8.dist-info/METADATA +157 -0
- libcom-0.1.8.dist-info/RECORD +310 -0
- libcom-0.1.8.dist-info/WHEEL +5 -0
- libcom-0.1.8.dist-info/licenses/LICENSE +201 -0
- libcom-0.1.8.dist-info/top_level.txt +1 -0
libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/body.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import math
|
|
3
|
+
import numpy as np
|
|
4
|
+
import time
|
|
5
|
+
import torch
|
|
6
|
+
from scipy.ndimage.filters import gaussian_filter
|
|
7
|
+
from torchvision import transforms
|
|
8
|
+
|
|
9
|
+
from . import util
|
|
10
|
+
from .model import bodypose_model
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Body(object):
|
|
14
|
+
|
|
15
|
+
def __init__(self, model_path):
|
|
16
|
+
self.model = bodypose_model()
|
|
17
|
+
if torch.cuda.is_available():
|
|
18
|
+
self.model = self.model.cuda()
|
|
19
|
+
print('cuda')
|
|
20
|
+
model_dict = util.transfer(self.model, torch.load(model_path))
|
|
21
|
+
self.model.load_state_dict(model_dict)
|
|
22
|
+
self.model.eval()
|
|
23
|
+
|
|
24
|
+
def __call__(self, oriImg):
|
|
25
|
+
# scale_search = [0.5, 1.0, 1.5, 2.0]
|
|
26
|
+
scale_search = [0.5]
|
|
27
|
+
boxsize = 368
|
|
28
|
+
stride = 8
|
|
29
|
+
padValue = 128
|
|
30
|
+
thre1 = 0.1
|
|
31
|
+
thre2 = 0.05
|
|
32
|
+
multiplier = [x * boxsize / oriImg.shape[0] for x in scale_search]
|
|
33
|
+
heatmap_avg = np.zeros((oriImg.shape[0], oriImg.shape[1], 19))
|
|
34
|
+
paf_avg = np.zeros((oriImg.shape[0], oriImg.shape[1], 38))
|
|
35
|
+
|
|
36
|
+
for m in range(len(multiplier)):
|
|
37
|
+
scale = multiplier[m]
|
|
38
|
+
imageToTest = cv2.resize(oriImg, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
|
|
39
|
+
imageToTest_padded, pad = util.padRightDownCorner(imageToTest, stride, padValue)
|
|
40
|
+
im = np.transpose(np.float32(imageToTest_padded[:, :, :, np.newaxis]), (3, 2, 0, 1)) / 256 - 0.5
|
|
41
|
+
im = np.ascontiguousarray(im)
|
|
42
|
+
|
|
43
|
+
data = torch.from_numpy(im).float()
|
|
44
|
+
if torch.cuda.is_available():
|
|
45
|
+
data = data.cuda()
|
|
46
|
+
# data = data.permute([2, 0, 1]).unsqueeze(0).float()
|
|
47
|
+
with torch.no_grad():
|
|
48
|
+
Mconv7_stage6_L1, Mconv7_stage6_L2 = self.model(data)
|
|
49
|
+
Mconv7_stage6_L1 = Mconv7_stage6_L1.cpu().numpy()
|
|
50
|
+
Mconv7_stage6_L2 = Mconv7_stage6_L2.cpu().numpy()
|
|
51
|
+
|
|
52
|
+
# extract outputs, resize, and remove padding
|
|
53
|
+
# heatmap = np.transpose(np.squeeze(net.blobs[output_blobs.keys()[1]].data), (1, 2, 0)) # output 1 is heatmaps
|
|
54
|
+
heatmap = np.transpose(np.squeeze(Mconv7_stage6_L2), (1, 2, 0)) # output 1 is heatmaps
|
|
55
|
+
heatmap = cv2.resize(heatmap, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC)
|
|
56
|
+
heatmap = heatmap[:imageToTest_padded.shape[0] - pad[2], :imageToTest_padded.shape[1] - pad[3], :]
|
|
57
|
+
heatmap = cv2.resize(heatmap, (oriImg.shape[1], oriImg.shape[0]), interpolation=cv2.INTER_CUBIC)
|
|
58
|
+
|
|
59
|
+
# paf = np.transpose(np.squeeze(net.blobs[output_blobs.keys()[0]].data), (1, 2, 0)) # output 0 is PAFs
|
|
60
|
+
paf = np.transpose(np.squeeze(Mconv7_stage6_L1), (1, 2, 0)) # output 0 is PAFs
|
|
61
|
+
paf = cv2.resize(paf, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC)
|
|
62
|
+
paf = paf[:imageToTest_padded.shape[0] - pad[2], :imageToTest_padded.shape[1] - pad[3], :]
|
|
63
|
+
paf = cv2.resize(paf, (oriImg.shape[1], oriImg.shape[0]), interpolation=cv2.INTER_CUBIC)
|
|
64
|
+
|
|
65
|
+
heatmap_avg += heatmap_avg + heatmap / len(multiplier)
|
|
66
|
+
paf_avg += +paf / len(multiplier)
|
|
67
|
+
|
|
68
|
+
all_peaks = []
|
|
69
|
+
peak_counter = 0
|
|
70
|
+
|
|
71
|
+
for part in range(18):
|
|
72
|
+
map_ori = heatmap_avg[:, :, part]
|
|
73
|
+
one_heatmap = gaussian_filter(map_ori, sigma=3)
|
|
74
|
+
|
|
75
|
+
map_left = np.zeros(one_heatmap.shape)
|
|
76
|
+
map_left[1:, :] = one_heatmap[:-1, :]
|
|
77
|
+
map_right = np.zeros(one_heatmap.shape)
|
|
78
|
+
map_right[:-1, :] = one_heatmap[1:, :]
|
|
79
|
+
map_up = np.zeros(one_heatmap.shape)
|
|
80
|
+
map_up[:, 1:] = one_heatmap[:, :-1]
|
|
81
|
+
map_down = np.zeros(one_heatmap.shape)
|
|
82
|
+
map_down[:, :-1] = one_heatmap[:, 1:]
|
|
83
|
+
|
|
84
|
+
peaks_binary = np.logical_and.reduce((one_heatmap >= map_left, one_heatmap >= map_right,
|
|
85
|
+
one_heatmap >= map_up, one_heatmap >= map_down, one_heatmap > thre1))
|
|
86
|
+
peaks = list(zip(np.nonzero(peaks_binary)[1], np.nonzero(peaks_binary)[0])) # note reverse
|
|
87
|
+
peaks_with_score = [x + (map_ori[x[1], x[0]], ) for x in peaks]
|
|
88
|
+
peak_id = range(peak_counter, peak_counter + len(peaks))
|
|
89
|
+
peaks_with_score_and_id = [peaks_with_score[i] + (peak_id[i], ) for i in range(len(peak_id))]
|
|
90
|
+
|
|
91
|
+
all_peaks.append(peaks_with_score_and_id)
|
|
92
|
+
peak_counter += len(peaks)
|
|
93
|
+
|
|
94
|
+
# find connection in the specified sequence, center 29 is in the position 15
|
|
95
|
+
limbSeq = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10], \
|
|
96
|
+
[10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17], \
|
|
97
|
+
[1, 16], [16, 18], [3, 17], [6, 18]]
|
|
98
|
+
# the middle joints heatmap correpondence
|
|
99
|
+
mapIdx = [[31, 32], [39, 40], [33, 34], [35, 36], [41, 42], [43, 44], [19, 20], [21, 22], \
|
|
100
|
+
[23, 24], [25, 26], [27, 28], [29, 30], [47, 48], [49, 50], [53, 54], [51, 52], \
|
|
101
|
+
[55, 56], [37, 38], [45, 46]]
|
|
102
|
+
|
|
103
|
+
connection_all = []
|
|
104
|
+
special_k = []
|
|
105
|
+
mid_num = 10
|
|
106
|
+
|
|
107
|
+
for k in range(len(mapIdx)):
|
|
108
|
+
score_mid = paf_avg[:, :, [x - 19 for x in mapIdx[k]]]
|
|
109
|
+
candA = all_peaks[limbSeq[k][0] - 1]
|
|
110
|
+
candB = all_peaks[limbSeq[k][1] - 1]
|
|
111
|
+
nA = len(candA)
|
|
112
|
+
nB = len(candB)
|
|
113
|
+
indexA, indexB = limbSeq[k]
|
|
114
|
+
if (nA != 0 and nB != 0):
|
|
115
|
+
connection_candidate = []
|
|
116
|
+
for i in range(nA):
|
|
117
|
+
for j in range(nB):
|
|
118
|
+
vec = np.subtract(candB[j][:2], candA[i][:2])
|
|
119
|
+
norm = math.sqrt(vec[0] * vec[0] + vec[1] * vec[1])
|
|
120
|
+
norm = max(0.001, norm)
|
|
121
|
+
vec = np.divide(vec, norm)
|
|
122
|
+
|
|
123
|
+
startend = list(zip(np.linspace(candA[i][0], candB[j][0], num=mid_num), \
|
|
124
|
+
np.linspace(candA[i][1], candB[j][1], num=mid_num)))
|
|
125
|
+
|
|
126
|
+
vec_x = np.array([score_mid[int(round(startend[I][1])), int(round(startend[I][0])), 0] \
|
|
127
|
+
for I in range(len(startend))])
|
|
128
|
+
vec_y = np.array([score_mid[int(round(startend[I][1])), int(round(startend[I][0])), 1] \
|
|
129
|
+
for I in range(len(startend))])
|
|
130
|
+
|
|
131
|
+
score_midpts = np.multiply(vec_x, vec[0]) + np.multiply(vec_y, vec[1])
|
|
132
|
+
score_with_dist_prior = sum(score_midpts) / len(score_midpts) + min(
|
|
133
|
+
0.5 * oriImg.shape[0] / norm - 1, 0)
|
|
134
|
+
criterion1 = len(np.nonzero(score_midpts > thre2)[0]) > 0.8 * len(score_midpts)
|
|
135
|
+
criterion2 = score_with_dist_prior > 0
|
|
136
|
+
if criterion1 and criterion2:
|
|
137
|
+
connection_candidate.append(
|
|
138
|
+
[i, j, score_with_dist_prior, score_with_dist_prior + candA[i][2] + candB[j][2]])
|
|
139
|
+
|
|
140
|
+
connection_candidate = sorted(connection_candidate, key=lambda x: x[2], reverse=True)
|
|
141
|
+
connection = np.zeros((0, 5))
|
|
142
|
+
for c in range(len(connection_candidate)):
|
|
143
|
+
i, j, s = connection_candidate[c][0:3]
|
|
144
|
+
if (i not in connection[:, 3] and j not in connection[:, 4]):
|
|
145
|
+
connection = np.vstack([connection, [candA[i][3], candB[j][3], s, i, j]])
|
|
146
|
+
if (len(connection) >= min(nA, nB)):
|
|
147
|
+
break
|
|
148
|
+
|
|
149
|
+
connection_all.append(connection)
|
|
150
|
+
else:
|
|
151
|
+
special_k.append(k)
|
|
152
|
+
connection_all.append([])
|
|
153
|
+
|
|
154
|
+
# last number in each row is the total parts number of that person
|
|
155
|
+
# the second last number in each row is the score of the overall configuration
|
|
156
|
+
subset = -1 * np.ones((0, 20))
|
|
157
|
+
candidate = np.array([item for sublist in all_peaks for item in sublist])
|
|
158
|
+
|
|
159
|
+
for k in range(len(mapIdx)):
|
|
160
|
+
if k not in special_k:
|
|
161
|
+
partAs = connection_all[k][:, 0]
|
|
162
|
+
partBs = connection_all[k][:, 1]
|
|
163
|
+
indexA, indexB = np.array(limbSeq[k]) - 1
|
|
164
|
+
|
|
165
|
+
for i in range(len(connection_all[k])): # = 1:size(temp,1)
|
|
166
|
+
found = 0
|
|
167
|
+
subset_idx = [-1, -1]
|
|
168
|
+
for j in range(len(subset)): # 1:size(subset,1):
|
|
169
|
+
if subset[j][indexA] == partAs[i] or subset[j][indexB] == partBs[i]:
|
|
170
|
+
subset_idx[found] = j
|
|
171
|
+
found += 1
|
|
172
|
+
|
|
173
|
+
if found == 1:
|
|
174
|
+
j = subset_idx[0]
|
|
175
|
+
if subset[j][indexB] != partBs[i]:
|
|
176
|
+
subset[j][indexB] = partBs[i]
|
|
177
|
+
subset[j][-1] += 1
|
|
178
|
+
subset[j][-2] += candidate[partBs[i].astype(int), 2] + connection_all[k][i][2]
|
|
179
|
+
elif found == 2: # if found 2 and disjoint, merge them
|
|
180
|
+
j1, j2 = subset_idx
|
|
181
|
+
membership = ((subset[j1] >= 0).astype(int) + (subset[j2] >= 0).astype(int))[:-2]
|
|
182
|
+
if len(np.nonzero(membership == 2)[0]) == 0: # merge
|
|
183
|
+
subset[j1][:-2] += (subset[j2][:-2] + 1)
|
|
184
|
+
subset[j1][-2:] += subset[j2][-2:]
|
|
185
|
+
subset[j1][-2] += connection_all[k][i][2]
|
|
186
|
+
subset = np.delete(subset, j2, 0)
|
|
187
|
+
else: # as like found == 1
|
|
188
|
+
subset[j1][indexB] = partBs[i]
|
|
189
|
+
subset[j1][-1] += 1
|
|
190
|
+
subset[j1][-2] += candidate[partBs[i].astype(int), 2] + connection_all[k][i][2]
|
|
191
|
+
|
|
192
|
+
# if find no partA in the subset, create a new subset
|
|
193
|
+
elif not found and k < 17:
|
|
194
|
+
row = -1 * np.ones(20)
|
|
195
|
+
row[indexA] = partAs[i]
|
|
196
|
+
row[indexB] = partBs[i]
|
|
197
|
+
row[-1] = 2
|
|
198
|
+
row[-2] = sum(candidate[connection_all[k][i, :2].astype(int), 2]) + connection_all[k][i][2]
|
|
199
|
+
subset = np.vstack([subset, row])
|
|
200
|
+
# delete some rows of subset which has few parts occur
|
|
201
|
+
deleteIdx = []
|
|
202
|
+
for i in range(len(subset)):
|
|
203
|
+
if subset[i][-1] < 4 or subset[i][-2] / subset[i][-1] < 0.4:
|
|
204
|
+
deleteIdx.append(i)
|
|
205
|
+
subset = np.delete(subset, deleteIdx, axis=0)
|
|
206
|
+
|
|
207
|
+
# subset: n*20 array, 0-17 is the index in candidate, 18 is the total score, 19 is the total parts
|
|
208
|
+
# candidate: x, y, score, id
|
|
209
|
+
return candidate, subset
|
libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/hand.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import json
|
|
3
|
+
import math
|
|
4
|
+
import numpy as np
|
|
5
|
+
import time
|
|
6
|
+
import torch
|
|
7
|
+
from scipy.ndimage.filters import gaussian_filter
|
|
8
|
+
from skimage.measure import label
|
|
9
|
+
|
|
10
|
+
from . import util
|
|
11
|
+
from .model import handpose_model
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Hand(object):
|
|
15
|
+
|
|
16
|
+
def __init__(self, model_path):
|
|
17
|
+
self.model = handpose_model()
|
|
18
|
+
if torch.cuda.is_available():
|
|
19
|
+
self.model = self.model.cuda()
|
|
20
|
+
print('cuda')
|
|
21
|
+
model_dict = util.transfer(self.model, torch.load(model_path))
|
|
22
|
+
self.model.load_state_dict(model_dict)
|
|
23
|
+
self.model.eval()
|
|
24
|
+
|
|
25
|
+
def __call__(self, oriImg):
|
|
26
|
+
scale_search = [0.5, 1.0, 1.5, 2.0]
|
|
27
|
+
# scale_search = [0.5]
|
|
28
|
+
boxsize = 368
|
|
29
|
+
stride = 8
|
|
30
|
+
padValue = 128
|
|
31
|
+
thre = 0.05
|
|
32
|
+
multiplier = [x * boxsize / oriImg.shape[0] for x in scale_search]
|
|
33
|
+
heatmap_avg = np.zeros((oriImg.shape[0], oriImg.shape[1], 22))
|
|
34
|
+
# paf_avg = np.zeros((oriImg.shape[0], oriImg.shape[1], 38))
|
|
35
|
+
|
|
36
|
+
for m in range(len(multiplier)):
|
|
37
|
+
scale = multiplier[m]
|
|
38
|
+
imageToTest = cv2.resize(oriImg, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
|
|
39
|
+
imageToTest_padded, pad = util.padRightDownCorner(imageToTest, stride, padValue)
|
|
40
|
+
im = np.transpose(np.float32(imageToTest_padded[:, :, :, np.newaxis]), (3, 2, 0, 1)) / 256 - 0.5
|
|
41
|
+
im = np.ascontiguousarray(im)
|
|
42
|
+
|
|
43
|
+
data = torch.from_numpy(im).float()
|
|
44
|
+
if torch.cuda.is_available():
|
|
45
|
+
data = data.cuda()
|
|
46
|
+
# data = data.permute([2, 0, 1]).unsqueeze(0).float()
|
|
47
|
+
with torch.no_grad():
|
|
48
|
+
output = self.model(data).cpu().numpy()
|
|
49
|
+
# output = self.model(data).numpy()q
|
|
50
|
+
|
|
51
|
+
# extract outputs, resize, and remove padding
|
|
52
|
+
heatmap = np.transpose(np.squeeze(output), (1, 2, 0)) # output 1 is heatmaps
|
|
53
|
+
heatmap = cv2.resize(heatmap, (0, 0), fx=stride, fy=stride, interpolation=cv2.INTER_CUBIC)
|
|
54
|
+
heatmap = heatmap[:imageToTest_padded.shape[0] - pad[2], :imageToTest_padded.shape[1] - pad[3], :]
|
|
55
|
+
heatmap = cv2.resize(heatmap, (oriImg.shape[1], oriImg.shape[0]), interpolation=cv2.INTER_CUBIC)
|
|
56
|
+
|
|
57
|
+
heatmap_avg += heatmap / len(multiplier)
|
|
58
|
+
|
|
59
|
+
all_peaks = []
|
|
60
|
+
for part in range(21):
|
|
61
|
+
map_ori = heatmap_avg[:, :, part]
|
|
62
|
+
one_heatmap = gaussian_filter(map_ori, sigma=3)
|
|
63
|
+
binary = np.ascontiguousarray(one_heatmap > thre, dtype=np.uint8)
|
|
64
|
+
# 全部小于阈值
|
|
65
|
+
if np.sum(binary) == 0:
|
|
66
|
+
all_peaks.append([0, 0])
|
|
67
|
+
continue
|
|
68
|
+
label_img, label_numbers = label(binary, return_num=True, connectivity=binary.ndim)
|
|
69
|
+
max_index = np.argmax([np.sum(map_ori[label_img == i]) for i in range(1, label_numbers + 1)]) + 1
|
|
70
|
+
label_img[label_img != max_index] = 0
|
|
71
|
+
map_ori[label_img == 0] = 0
|
|
72
|
+
|
|
73
|
+
y, x = util.npmax(map_ori)
|
|
74
|
+
all_peaks.append([x, y])
|
|
75
|
+
return np.array(all_peaks)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import torch.nn as nn
|
|
3
|
+
from collections import OrderedDict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def make_layers(block, no_relu_layers):
|
|
7
|
+
layers = []
|
|
8
|
+
for layer_name, v in block.items():
|
|
9
|
+
if 'pool' in layer_name:
|
|
10
|
+
layer = nn.MaxPool2d(kernel_size=v[0], stride=v[1], padding=v[2])
|
|
11
|
+
layers.append((layer_name, layer))
|
|
12
|
+
else:
|
|
13
|
+
conv2d = nn.Conv2d(in_channels=v[0], out_channels=v[1], kernel_size=v[2], stride=v[3], padding=v[4])
|
|
14
|
+
layers.append((layer_name, conv2d))
|
|
15
|
+
if layer_name not in no_relu_layers:
|
|
16
|
+
layers.append(('relu_' + layer_name, nn.ReLU(inplace=True)))
|
|
17
|
+
|
|
18
|
+
return nn.Sequential(OrderedDict(layers))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class bodypose_model(nn.Module):
|
|
22
|
+
|
|
23
|
+
def __init__(self):
|
|
24
|
+
super(bodypose_model, self).__init__()
|
|
25
|
+
|
|
26
|
+
# these layers have no relu layer
|
|
27
|
+
no_relu_layers = ['conv5_5_CPM_L1', 'conv5_5_CPM_L2', 'Mconv7_stage2_L1',\
|
|
28
|
+
'Mconv7_stage2_L2', 'Mconv7_stage3_L1', 'Mconv7_stage3_L2',\
|
|
29
|
+
'Mconv7_stage4_L1', 'Mconv7_stage4_L2', 'Mconv7_stage5_L1',\
|
|
30
|
+
'Mconv7_stage5_L2', 'Mconv7_stage6_L1', 'Mconv7_stage6_L1']
|
|
31
|
+
blocks = {}
|
|
32
|
+
block0 = OrderedDict([('conv1_1', [3, 64, 3, 1, 1]), ('conv1_2', [64, 64, 3, 1, 1]), ('pool1_stage1', [2, 2,
|
|
33
|
+
0]),
|
|
34
|
+
('conv2_1', [64, 128, 3, 1, 1]), ('conv2_2', [128, 128, 3, 1, 1]),
|
|
35
|
+
('pool2_stage1', [2, 2, 0]), ('conv3_1', [128, 256, 3, 1, 1]),
|
|
36
|
+
('conv3_2', [256, 256, 3, 1, 1]), ('conv3_3', [256, 256, 3, 1, 1]),
|
|
37
|
+
('conv3_4', [256, 256, 3, 1, 1]), ('pool3_stage1', [2, 2, 0]),
|
|
38
|
+
('conv4_1', [256, 512, 3, 1, 1]), ('conv4_2', [512, 512, 3, 1, 1]),
|
|
39
|
+
('conv4_3_CPM', [512, 256, 3, 1, 1]), ('conv4_4_CPM', [256, 128, 3, 1, 1])])
|
|
40
|
+
|
|
41
|
+
# Stage 1
|
|
42
|
+
block1_1 = OrderedDict([('conv5_1_CPM_L1', [128, 128, 3, 1, 1]), ('conv5_2_CPM_L1', [128, 128, 3, 1, 1]),
|
|
43
|
+
('conv5_3_CPM_L1', [128, 128, 3, 1, 1]), ('conv5_4_CPM_L1', [128, 512, 1, 1, 0]),
|
|
44
|
+
('conv5_5_CPM_L1', [512, 38, 1, 1, 0])])
|
|
45
|
+
|
|
46
|
+
block1_2 = OrderedDict([('conv5_1_CPM_L2', [128, 128, 3, 1, 1]), ('conv5_2_CPM_L2', [128, 128, 3, 1, 1]),
|
|
47
|
+
('conv5_3_CPM_L2', [128, 128, 3, 1, 1]), ('conv5_4_CPM_L2', [128, 512, 1, 1, 0]),
|
|
48
|
+
('conv5_5_CPM_L2', [512, 19, 1, 1, 0])])
|
|
49
|
+
blocks['block1_1'] = block1_1
|
|
50
|
+
blocks['block1_2'] = block1_2
|
|
51
|
+
|
|
52
|
+
self.model0 = make_layers(block0, no_relu_layers)
|
|
53
|
+
|
|
54
|
+
# Stages 2 - 6
|
|
55
|
+
for i in range(2, 7):
|
|
56
|
+
blocks['block%d_1' % i] = OrderedDict([('Mconv1_stage%d_L1' % i, [185, 128, 7, 1, 3]),
|
|
57
|
+
('Mconv2_stage%d_L1' % i, [128, 128, 7, 1, 3]),
|
|
58
|
+
('Mconv3_stage%d_L1' % i, [128, 128, 7, 1, 3]),
|
|
59
|
+
('Mconv4_stage%d_L1' % i, [128, 128, 7, 1, 3]),
|
|
60
|
+
('Mconv5_stage%d_L1' % i, [128, 128, 7, 1, 3]),
|
|
61
|
+
('Mconv6_stage%d_L1' % i, [128, 128, 1, 1, 0]),
|
|
62
|
+
('Mconv7_stage%d_L1' % i, [128, 38, 1, 1, 0])])
|
|
63
|
+
|
|
64
|
+
blocks['block%d_2' % i] = OrderedDict([('Mconv1_stage%d_L2' % i, [185, 128, 7, 1, 3]),
|
|
65
|
+
('Mconv2_stage%d_L2' % i, [128, 128, 7, 1, 3]),
|
|
66
|
+
('Mconv3_stage%d_L2' % i, [128, 128, 7, 1, 3]),
|
|
67
|
+
('Mconv4_stage%d_L2' % i, [128, 128, 7, 1, 3]),
|
|
68
|
+
('Mconv5_stage%d_L2' % i, [128, 128, 7, 1, 3]),
|
|
69
|
+
('Mconv6_stage%d_L2' % i, [128, 128, 1, 1, 0]),
|
|
70
|
+
('Mconv7_stage%d_L2' % i, [128, 19, 1, 1, 0])])
|
|
71
|
+
|
|
72
|
+
for k in blocks.keys():
|
|
73
|
+
blocks[k] = make_layers(blocks[k], no_relu_layers)
|
|
74
|
+
|
|
75
|
+
self.model1_1 = blocks['block1_1']
|
|
76
|
+
self.model2_1 = blocks['block2_1']
|
|
77
|
+
self.model3_1 = blocks['block3_1']
|
|
78
|
+
self.model4_1 = blocks['block4_1']
|
|
79
|
+
self.model5_1 = blocks['block5_1']
|
|
80
|
+
self.model6_1 = blocks['block6_1']
|
|
81
|
+
|
|
82
|
+
self.model1_2 = blocks['block1_2']
|
|
83
|
+
self.model2_2 = blocks['block2_2']
|
|
84
|
+
self.model3_2 = blocks['block3_2']
|
|
85
|
+
self.model4_2 = blocks['block4_2']
|
|
86
|
+
self.model5_2 = blocks['block5_2']
|
|
87
|
+
self.model6_2 = blocks['block6_2']
|
|
88
|
+
|
|
89
|
+
def forward(self, x):
|
|
90
|
+
|
|
91
|
+
out1 = self.model0(x)
|
|
92
|
+
|
|
93
|
+
out1_1 = self.model1_1(out1)
|
|
94
|
+
out1_2 = self.model1_2(out1)
|
|
95
|
+
out2 = torch.cat([out1_1, out1_2, out1], 1)
|
|
96
|
+
|
|
97
|
+
out2_1 = self.model2_1(out2)
|
|
98
|
+
out2_2 = self.model2_2(out2)
|
|
99
|
+
out3 = torch.cat([out2_1, out2_2, out1], 1)
|
|
100
|
+
|
|
101
|
+
out3_1 = self.model3_1(out3)
|
|
102
|
+
out3_2 = self.model3_2(out3)
|
|
103
|
+
out4 = torch.cat([out3_1, out3_2, out1], 1)
|
|
104
|
+
|
|
105
|
+
out4_1 = self.model4_1(out4)
|
|
106
|
+
out4_2 = self.model4_2(out4)
|
|
107
|
+
out5 = torch.cat([out4_1, out4_2, out1], 1)
|
|
108
|
+
|
|
109
|
+
out5_1 = self.model5_1(out5)
|
|
110
|
+
out5_2 = self.model5_2(out5)
|
|
111
|
+
out6 = torch.cat([out5_1, out5_2, out1], 1)
|
|
112
|
+
|
|
113
|
+
out6_1 = self.model6_1(out6)
|
|
114
|
+
out6_2 = self.model6_2(out6)
|
|
115
|
+
|
|
116
|
+
return out6_1, out6_2
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class handpose_model(nn.Module):
|
|
120
|
+
|
|
121
|
+
def __init__(self):
|
|
122
|
+
super(handpose_model, self).__init__()
|
|
123
|
+
|
|
124
|
+
# these layers have no relu layer
|
|
125
|
+
no_relu_layers = ['conv6_2_CPM', 'Mconv7_stage2', 'Mconv7_stage3',\
|
|
126
|
+
'Mconv7_stage4', 'Mconv7_stage5', 'Mconv7_stage6']
|
|
127
|
+
# stage 1
|
|
128
|
+
block1_0 = OrderedDict([('conv1_1', [3, 64, 3, 1, 1]), ('conv1_2', [64, 64, 3, 1, 1]),
|
|
129
|
+
('pool1_stage1', [2, 2, 0]), ('conv2_1', [64, 128, 3, 1, 1]),
|
|
130
|
+
('conv2_2', [128, 128, 3, 1, 1]), ('pool2_stage1', [2, 2, 0]),
|
|
131
|
+
('conv3_1', [128, 256, 3, 1, 1]), ('conv3_2', [256, 256, 3, 1, 1]),
|
|
132
|
+
('conv3_3', [256, 256, 3, 1, 1]), ('conv3_4', [256, 256, 3, 1, 1]),
|
|
133
|
+
('pool3_stage1', [2, 2, 0]), ('conv4_1', [256, 512, 3, 1, 1]),
|
|
134
|
+
('conv4_2', [512, 512, 3, 1, 1]), ('conv4_3', [512, 512, 3, 1, 1]),
|
|
135
|
+
('conv4_4', [512, 512, 3, 1, 1]), ('conv5_1', [512, 512, 3, 1, 1]),
|
|
136
|
+
('conv5_2', [512, 512, 3, 1, 1]), ('conv5_3_CPM', [512, 128, 3, 1, 1])])
|
|
137
|
+
|
|
138
|
+
block1_1 = OrderedDict([('conv6_1_CPM', [128, 512, 1, 1, 0]), ('conv6_2_CPM', [512, 22, 1, 1, 0])])
|
|
139
|
+
|
|
140
|
+
blocks = {}
|
|
141
|
+
blocks['block1_0'] = block1_0
|
|
142
|
+
blocks['block1_1'] = block1_1
|
|
143
|
+
|
|
144
|
+
# stage 2-6
|
|
145
|
+
for i in range(2, 7):
|
|
146
|
+
blocks['block%d' % i] = OrderedDict([('Mconv1_stage%d' % i, [150, 128, 7, 1, 3]),
|
|
147
|
+
('Mconv2_stage%d' % i, [128, 128, 7, 1, 3]),
|
|
148
|
+
('Mconv3_stage%d' % i, [128, 128, 7, 1, 3]),
|
|
149
|
+
('Mconv4_stage%d' % i, [128, 128, 7, 1, 3]),
|
|
150
|
+
('Mconv5_stage%d' % i, [128, 128, 7, 1, 3]),
|
|
151
|
+
('Mconv6_stage%d' % i, [128, 128, 1, 1, 0]),
|
|
152
|
+
('Mconv7_stage%d' % i, [128, 22, 1, 1, 0])])
|
|
153
|
+
|
|
154
|
+
for k in blocks.keys():
|
|
155
|
+
blocks[k] = make_layers(blocks[k], no_relu_layers)
|
|
156
|
+
|
|
157
|
+
self.model1_0 = blocks['block1_0']
|
|
158
|
+
self.model1_1 = blocks['block1_1']
|
|
159
|
+
self.model2 = blocks['block2']
|
|
160
|
+
self.model3 = blocks['block3']
|
|
161
|
+
self.model4 = blocks['block4']
|
|
162
|
+
self.model5 = blocks['block5']
|
|
163
|
+
self.model6 = blocks['block6']
|
|
164
|
+
|
|
165
|
+
def forward(self, x):
|
|
166
|
+
out1_0 = self.model1_0(x)
|
|
167
|
+
out1_1 = self.model1_1(out1_0)
|
|
168
|
+
concat_stage2 = torch.cat([out1_1, out1_0], 1)
|
|
169
|
+
out_stage2 = self.model2(concat_stage2)
|
|
170
|
+
concat_stage3 = torch.cat([out_stage2, out1_0], 1)
|
|
171
|
+
out_stage3 = self.model3(concat_stage3)
|
|
172
|
+
concat_stage4 = torch.cat([out_stage3, out1_0], 1)
|
|
173
|
+
out_stage4 = self.model4(concat_stage4)
|
|
174
|
+
concat_stage5 = torch.cat([out_stage4, out1_0], 1)
|
|
175
|
+
out_stage5 = self.model5(concat_stage5)
|
|
176
|
+
concat_stage6 = torch.cat([out_stage5, out1_0], 1)
|
|
177
|
+
out_stage6 = self.model6(concat_stage6)
|
|
178
|
+
return out_stage6
|
libcom/painterly_image_harmonization/source/PHDiffusion/ldm/modules/extra_condition/openpose/util.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import cv2
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def padRightDownCorner(img, stride, padValue):
|
|
8
|
+
h = img.shape[0]
|
|
9
|
+
w = img.shape[1]
|
|
10
|
+
|
|
11
|
+
pad = 4 * [None]
|
|
12
|
+
pad[0] = 0 # up
|
|
13
|
+
pad[1] = 0 # left
|
|
14
|
+
pad[2] = 0 if (h % stride == 0) else stride - (h % stride) # down
|
|
15
|
+
pad[3] = 0 if (w % stride == 0) else stride - (w % stride) # right
|
|
16
|
+
|
|
17
|
+
img_padded = img
|
|
18
|
+
pad_up = np.tile(img_padded[0:1, :, :] * 0 + padValue, (pad[0], 1, 1))
|
|
19
|
+
img_padded = np.concatenate((pad_up, img_padded), axis=0)
|
|
20
|
+
pad_left = np.tile(img_padded[:, 0:1, :] * 0 + padValue, (1, pad[1], 1))
|
|
21
|
+
img_padded = np.concatenate((pad_left, img_padded), axis=1)
|
|
22
|
+
pad_down = np.tile(img_padded[-2:-1, :, :] * 0 + padValue, (pad[2], 1, 1))
|
|
23
|
+
img_padded = np.concatenate((img_padded, pad_down), axis=0)
|
|
24
|
+
pad_right = np.tile(img_padded[:, -2:-1, :] * 0 + padValue, (1, pad[3], 1))
|
|
25
|
+
img_padded = np.concatenate((img_padded, pad_right), axis=1)
|
|
26
|
+
|
|
27
|
+
return img_padded, pad
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# transfer caffe model to pytorch which will match the layer name
|
|
31
|
+
def transfer(model, model_weights):
|
|
32
|
+
transfered_model_weights = {}
|
|
33
|
+
for weights_name in model.state_dict().keys():
|
|
34
|
+
transfered_model_weights[weights_name] = model_weights['.'.join(weights_name.split('.')[1:])]
|
|
35
|
+
return transfered_model_weights
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# draw the body keypoint and lims
|
|
39
|
+
def draw_bodypose(canvas, candidate, subset):
|
|
40
|
+
stickwidth = 4
|
|
41
|
+
limbSeq = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10], \
|
|
42
|
+
[10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17], \
|
|
43
|
+
[1, 16], [16, 18], [3, 17], [6, 18]]
|
|
44
|
+
|
|
45
|
+
colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0], \
|
|
46
|
+
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255], \
|
|
47
|
+
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]]
|
|
48
|
+
for i in range(18):
|
|
49
|
+
for n in range(len(subset)):
|
|
50
|
+
index = int(subset[n][i])
|
|
51
|
+
if index == -1:
|
|
52
|
+
continue
|
|
53
|
+
x, y = candidate[index][0:2]
|
|
54
|
+
cv2.circle(canvas, (int(x), int(y)), 4, colors[i], thickness=-1)
|
|
55
|
+
for i in range(17):
|
|
56
|
+
for n in range(len(subset)):
|
|
57
|
+
index = subset[n][np.array(limbSeq[i]) - 1]
|
|
58
|
+
if -1 in index:
|
|
59
|
+
continue
|
|
60
|
+
cur_canvas = canvas.copy()
|
|
61
|
+
Y = candidate[index.astype(int), 0]
|
|
62
|
+
X = candidate[index.astype(int), 1]
|
|
63
|
+
mX = np.mean(X)
|
|
64
|
+
mY = np.mean(Y)
|
|
65
|
+
length = ((X[0] - X[1])**2 + (Y[0] - Y[1])**2)**0.5
|
|
66
|
+
angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
|
|
67
|
+
polygon = cv2.ellipse2Poly((int(mY), int(mX)), (int(length / 2), stickwidth), int(angle), 0, 360, 1)
|
|
68
|
+
cv2.fillConvexPoly(cur_canvas, polygon, colors[i])
|
|
69
|
+
canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0)
|
|
70
|
+
# plt.imsave("preview.jpg", canvas[:, :, [2, 1, 0]])
|
|
71
|
+
# plt.imshow(canvas[:, :, [2, 1, 0]])
|
|
72
|
+
return canvas
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# image drawed by opencv is not good.
|
|
76
|
+
def draw_handpose(canvas, all_hand_peaks, show_number=False):
|
|
77
|
+
import matplotlib
|
|
78
|
+
edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [5, 6], [6, 7], [7, 8], [0, 9], [9, 10], \
|
|
79
|
+
[10, 11], [11, 12], [0, 13], [13, 14], [14, 15], [15, 16], [0, 17], [17, 18], [18, 19], [19, 20]]
|
|
80
|
+
|
|
81
|
+
for peaks in all_hand_peaks:
|
|
82
|
+
for ie, e in enumerate(edges):
|
|
83
|
+
if np.sum(np.all(peaks[e], axis=1) == 0) == 0:
|
|
84
|
+
x1, y1 = peaks[e[0]]
|
|
85
|
+
x2, y2 = peaks[e[1]]
|
|
86
|
+
cv2.line(
|
|
87
|
+
canvas, (x1, y1), (x2, y2),
|
|
88
|
+
matplotlib.colors.hsv_to_rgb([ie / float(len(edges)), 1.0, 1.0]) * 255,
|
|
89
|
+
thickness=2)
|
|
90
|
+
|
|
91
|
+
for i, keyponit in enumerate(peaks):
|
|
92
|
+
x, y = keyponit
|
|
93
|
+
cv2.circle(canvas, (x, y), 4, (0, 0, 255), thickness=-1)
|
|
94
|
+
if show_number:
|
|
95
|
+
cv2.putText(canvas, str(i), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (0, 0, 0), lineType=cv2.LINE_AA)
|
|
96
|
+
return canvas
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# detect hand according to body pose keypoints
|
|
100
|
+
# please refer to https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/hand/handDetector.cpp
|
|
101
|
+
def handDetect(candidate, subset, oriImg):
|
|
102
|
+
# right hand: wrist 4, elbow 3, shoulder 2
|
|
103
|
+
# left hand: wrist 7, elbow 6, shoulder 5
|
|
104
|
+
ratioWristElbow = 0.33
|
|
105
|
+
detect_result = []
|
|
106
|
+
image_height, image_width = oriImg.shape[0:2]
|
|
107
|
+
for person in subset.astype(int):
|
|
108
|
+
# if any of three not detected
|
|
109
|
+
has_left = np.sum(person[[5, 6, 7]] == -1) == 0
|
|
110
|
+
has_right = np.sum(person[[2, 3, 4]] == -1) == 0
|
|
111
|
+
if not (has_left or has_right):
|
|
112
|
+
continue
|
|
113
|
+
hands = []
|
|
114
|
+
#left hand
|
|
115
|
+
if has_left:
|
|
116
|
+
left_shoulder_index, left_elbow_index, left_wrist_index = person[[5, 6, 7]]
|
|
117
|
+
x1, y1 = candidate[left_shoulder_index][:2]
|
|
118
|
+
x2, y2 = candidate[left_elbow_index][:2]
|
|
119
|
+
x3, y3 = candidate[left_wrist_index][:2]
|
|
120
|
+
hands.append([x1, y1, x2, y2, x3, y3, True])
|
|
121
|
+
# right hand
|
|
122
|
+
if has_right:
|
|
123
|
+
right_shoulder_index, right_elbow_index, right_wrist_index = person[[2, 3, 4]]
|
|
124
|
+
x1, y1 = candidate[right_shoulder_index][:2]
|
|
125
|
+
x2, y2 = candidate[right_elbow_index][:2]
|
|
126
|
+
x3, y3 = candidate[right_wrist_index][:2]
|
|
127
|
+
hands.append([x1, y1, x2, y2, x3, y3, False])
|
|
128
|
+
|
|
129
|
+
for x1, y1, x2, y2, x3, y3, is_left in hands:
|
|
130
|
+
# pos_hand = pos_wrist + ratio * (pos_wrist - pos_elbox) = (1 + ratio) * pos_wrist - ratio * pos_elbox
|
|
131
|
+
# handRectangle.x = posePtr[wrist*3] + ratioWristElbow * (posePtr[wrist*3] - posePtr[elbow*3]);
|
|
132
|
+
# handRectangle.y = posePtr[wrist*3+1] + ratioWristElbow * (posePtr[wrist*3+1] - posePtr[elbow*3+1]);
|
|
133
|
+
# const auto distanceWristElbow = getDistance(poseKeypoints, person, wrist, elbow);
|
|
134
|
+
# const auto distanceElbowShoulder = getDistance(poseKeypoints, person, elbow, shoulder);
|
|
135
|
+
# handRectangle.width = 1.5f * fastMax(distanceWristElbow, 0.9f * distanceElbowShoulder);
|
|
136
|
+
x = x3 + ratioWristElbow * (x3 - x2)
|
|
137
|
+
y = y3 + ratioWristElbow * (y3 - y2)
|
|
138
|
+
distanceWristElbow = math.sqrt((x3 - x2)**2 + (y3 - y2)**2)
|
|
139
|
+
distanceElbowShoulder = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
|
140
|
+
width = 1.5 * max(distanceWristElbow, 0.9 * distanceElbowShoulder)
|
|
141
|
+
# x-y refers to the center --> offset to topLeft point
|
|
142
|
+
# handRectangle.x -= handRectangle.width / 2.f;
|
|
143
|
+
# handRectangle.y -= handRectangle.height / 2.f;
|
|
144
|
+
x -= width / 2
|
|
145
|
+
y -= width / 2 # width = height
|
|
146
|
+
# overflow the image
|
|
147
|
+
if x < 0: x = 0
|
|
148
|
+
if y < 0: y = 0
|
|
149
|
+
width1 = width
|
|
150
|
+
width2 = width
|
|
151
|
+
if x + width > image_width: width1 = image_width - x
|
|
152
|
+
if y + width > image_height: width2 = image_height - y
|
|
153
|
+
width = min(width1, width2)
|
|
154
|
+
# the max hand box value is 20 pixels
|
|
155
|
+
if width >= 20:
|
|
156
|
+
detect_result.append([int(x), int(y), int(width), is_left])
|
|
157
|
+
'''
|
|
158
|
+
return value: [[x, y, w, True if left hand else False]].
|
|
159
|
+
width=height since the network require squared input.
|
|
160
|
+
x, y is the coordinate of top left
|
|
161
|
+
'''
|
|
162
|
+
return detect_result
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# get max index of 2d array
|
|
166
|
+
def npmax(array):
|
|
167
|
+
arrayindex = array.argmax(1)
|
|
168
|
+
arrayvalue = array.max(1)
|
|
169
|
+
i = arrayvalue.argmax()
|
|
170
|
+
j = arrayindex[i]
|
|
171
|
+
return i, j
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def HWC3(x):
|
|
175
|
+
assert x.dtype == np.uint8
|
|
176
|
+
if x.ndim == 2:
|
|
177
|
+
x = x[:, :, None]
|
|
178
|
+
assert x.ndim == 3
|
|
179
|
+
H, W, C = x.shape
|
|
180
|
+
assert C == 1 or C == 3 or C == 4
|
|
181
|
+
if C == 3:
|
|
182
|
+
return x
|
|
183
|
+
if C == 1:
|
|
184
|
+
return np.concatenate([x, x, x], axis=2)
|
|
185
|
+
if C == 4:
|
|
186
|
+
color = x[:, :, 0:3].astype(np.float32)
|
|
187
|
+
alpha = x[:, :, 3:4].astype(np.float32) / 255.0
|
|
188
|
+
y = color * alpha + 255.0 * (1.0 - alpha)
|
|
189
|
+
y = y.clip(0, 255).astype(np.uint8)
|
|
190
|
+
return y
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def resize_image(input_image, resolution):
|
|
194
|
+
H, W, C = input_image.shape
|
|
195
|
+
H = float(H)
|
|
196
|
+
W = float(W)
|
|
197
|
+
k = float(resolution) / min(H, W)
|
|
198
|
+
H *= k
|
|
199
|
+
W *= k
|
|
200
|
+
H = int(np.round(H / 64.0)) * 64
|
|
201
|
+
W = int(np.round(W / 64.0)) * 64
|
|
202
|
+
img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
|
|
203
|
+
return img
|