深度学习系列66:试穿模型IDM-VTON上手

本文介绍了IDM-VTON模型的结构,包括高级语义网络IP-Adapter和低级语义网络GarmentNet,以及如何通过HuggingFace的示例快速上手。详细步骤涉及下载预训练模型并配置环境以实现实时衣物换人效果。
摘要由CSDN通过智能技术生成

1. 模型概述

在这里插入图片描述
如图,总体流程为:

  1. 输入为:衣服的编码xg;人物+noise的编码xt;人物身上衣物的mask和人体pose分割(densepose);
  2. 衣服部分经过两部分网络:1)高级语义网络IP-Adapter:是一个图像编码器,比如CLIP模型;2)低级语义网络:称为GarmentNet,是一个UNet,用来提取图像低级细节特征,例如纹理,图案等等。
  3. 人体部分经过TryonNet,也是一个UNet。其输入和GarmentNet同层进行拼接后,输入自注意力层,然后取左半部分,与IPAdaper的结果,以及文本编码结果进行交叉注意力计算。

官网为:https://idm-vton.github.io/
不同模型的效果对比图如下:
在这里插入图片描述

2. 快速上手

可以在huggingface的demo上进行尝试:https://hf-mirror.com/spaces/yisol/IDM-VTON
参考https://github.com/camenduru/IDM-VTON-jupyter/blob/main/IDM_VTON_jupyter.ipynb,执行代码:

git clone  https://hub.nuaa.cf/camenduru/IDM-VTON-hf
cd IDM-VTON-hf
apt -y install -qq aria2
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/camenduru/IDM-VTON/resolve/main/densepose/model_final_162be9.pkl -d /content/IDM-VTON-hf/ckpt/densepose -o model_final_162be9.pkl
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/camenduru/IDM-VTON/resolve/main/humanparsing/parsing_atr.onnx -d /content/IDM-VTON-hf/ckpt/humanparsing -o parsing_atr.onnx
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/camenduru/IDM-VTON/resolve/main/humanparsing/parsing_lip.onnx -d /content/IDM-VTON-hf/ckpt/humanparsing -o parsing_lip.onnx
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/camenduru/IDM-VTON/resolve/main/openpose/ckpts/body_pose_model.pth -d /content/IDM-VTON-hf/ckpt/openpose/ckpts -o body_pose_model.pth
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/camenduru/IDM-VTON/resolve/main/IDM-VTON-DC/unet/diffusion_pytorch_model.bin -d /content/IDM-VTON-hf/ckpt/openpose/ckpts/unet -o diffusion_pytorch_model.bin
aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/camenduru/IDM-VTON/resolve/main/IDM-VTON-DC/unet/config.json -d /content/IDM-VTON-hf/ckpt/openpose/ckpts/unet -o config.json

pip install -q diffusers==0.25.0 accelerate==0.26.1 einops==0.7.0 onnxruntime==1.16.2 cloudpickle omegaconf gradio==4.24.0 fvcore av config spaces -i https://pypi.tuna.tsinghua.edu.cn/simple

然后执行python app.py启动应用即可
另外下载的模型也可以替换为F16的版本,参考:https://hf-mirror.com/camenduru/IDM-VTON-F16/tree/main

SUMO-idm跟驰模型是一种基于间距-速度控制的车辆跟驰模型,其代码实现如下: ```python class IDMVehicle(AVLaneVehicle): """ A vehicle using the IDM acceleration model. This vehicle implements the IDM car-following model. Additionally, it may use the MOBIL lane-changing model to change lanes. Parameters ---------- * see parents * idm_params : dict, optional Dictionary with parameters for the IDM model. The default value is `{'a': 1.3, 'b': 2.0, 'v0': 30, 'T': 1.5, 's0': 2, 'delta': 4}`. For a description of the parameters, please refer to the `IDM model wikipedia page <https://en.wikipedia.org/wiki/Intelligent_driver_model>`_. Notes ----- The MOBIL model is only used if the `lane_change_controller` is set to a `MobilLaneChanger` instance. Examples -------- >>> from flow.controllers import IDMController, ContinuousRouter >>> from flow.core.params import VehicleParams, SumoParams >>> >>> sumo_params = SumoParams(sim_step=0.1, render=False) >>> vehicle_params = VehicleParams() >>> vehicle_params.add( ... "human", ... acceleration_controller=(IDMController, {}), ... routing_controller=(ContinuousRouter, {}), ... num_vehicles=20) >>> >>> # create a network and a scenario >>> from flow.networks import HighwayNetwork >>> from flow.scenarios import Scenario >>> from flow.core.params import NetParams >>> from flow.core.params import InitialConfig >>> from flow.scenarios import HighwayScenario >>> from flow.envs.ring.accel import IDMVehicle >>> >>> network = HighwayNetwork( ... name='highway', ... vehicles=vehicle_params, ... net_params=NetParams(), ... initial_config=InitialConfig( ... spacing="uniform", ... lanes_distribution=float("inf"), ... lanes_count=2 ... ) ... ) >>> scenario = HighwayScenario( ... name='highway', ... generator_class=HighwayGenerator, ... vehicles=vehicle_params, ... net_params=NetParams(), ... initial_config=InitialConfig( ... spacing="uniform", ... lanes_distribution=float("inf"), ... lanes_count=2 ... ) ... ) >>> >>> # create the environment >>> from flow.envs import HighwayPOEnv >>> env = HighwayPOEnv( ... env_params=EnvParams(), ... sim_params=sumo_params, ... scenario=scenario, ... simulator='traci' ... ) >>> >>> # run the simulation >>> obs = env.reset() >>> for i in range(100): ... action = [1, 0] ... obs, rewards, dones, info = env.step(action) ... if i % 10 == 0: ... env.render() >>> env.close() """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.idm_params = kwargs.get( "idm_params", {'a': 1.3, 'b': 2.0, 'v0': 30, 'T': 1.5, 's0': 2, 'delta': 4}) def get_accel(self, env): """See parent class.""" leader = self.get_leader(env) if leader is None: return self.idm_params["a"] v = env.k.vehicle.get_speed(self.id) v_leader = env.k.vehicle.get_speed(leader) dv = max(0, v_leader - v) s = env.k.vehicle.get_headway(self.id) s_star = self.idm_params["s0"] + max( 0, v * self.idm_params["T"] + v * dv / (2 * np.sqrt(self.idm_params["a"] * self.idm_params["b"]))) return self.idm_params["a"] * ( 1 - np.power(v / self.idm_params["v0"], self.idm_params["delta"]) - np.power(s_star / s, 2)) ``` 其中,`get_accel`方法是计算车辆加速度的主要函数。在该函数中,根据跟驰模型的公式计算出车辆的期望车头间距`s_star`,然后根据该期望车头间距计算车辆的加速度。具体来说,该模型主要包含以下几个参数: - `a`:车辆加速度的最大值; - `b`:车辆减速度的最大值; - `v0`:车辆的期望速度; - `T`:期望的时间间隔,即车辆跟前车保持的时间间隔; - `s0`:车辆的最小车头间距; - `delta`:车辆速度对加速度的影响因子。 通过调整这些参数,可以对车辆的行为进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值