diffusion model(十四): prompt-to-prompt 深度剖析

news2024/9/20 16:09:03
info
paperPrompt-to-Prompt Image Editing with Cross Attention Control
githubhttps://github.com/google/prompt-to-prompt
Org:Google Research
个人复现https://github.com/myhz0606/diffusion_learning
个人博客主页http://myhz0606.com/article/p2p

1 前言

基于扩散模型(diffusion model)的图片编辑技术当下取得了飞跃的进展,涌现出了大量优秀的工作,例如:InstructPix2Pix[1]和EmuEdit[2]。这些工作致力于实现直接通过文字指令来编辑图片,极大地提升了传统图像编辑流程的效率。这种新兴的技术领域被称作基于指令的图像编辑(instruction-based image editing)。饮水思源,这类技术成功的背后,离不开Google在2022年提出的Prompt-to-Prompt(下文简称为p2p)这项工作。

为了深入理解技术细节,笔者借鉴google的开源代码对其进行复现。

2 P2P提出的Motivation

目前大火的文生图技术(text to image),给定一段文本(prompt)和随机种子,文生图模型会基于这两者生成一张图片。生成图片的不同由两个变量决定

  • 随机种子。随机种子决定初始的噪声 x T x_T xT
  • prompt。prompt是通过文本编码器(如CLIP的text encoder)转为语义向量再送入到diffusion modelcross-attention层中与图片信息交互。

假定up sampler不引入随机性,如DDIM; classifier-guidance-score; generation step是系统变量维持不变

如果我们固定了随机种子,仅微小的改变prompt,输出的图片是否相似?如果可行,那么根据这个特性,很方便的可以通过修改prompt来编辑图片了。很遗憾,事情没有那么简单。仅微小改动prompt,输出的图片也有很大差异。下图展示了固定随机种子,仅更改蛋糕种类的生成结果。

在这里插入图片描述

过去为了解决上述问题,Repaint[3]、Diffedit[4]在做图片编辑时,会引入一个mask,在编辑阶段,只更新mask区域的像素值,这类方法也取得了一些令人惊叹的结果,但上述方法同样存在三个问题:

  1. 需要手动构建mask,比较麻烦。(现在一般会接入SAM[5]来加速这个过程)
  2. 由于在编辑过程只修改mask区域的像素值,未考虑mask区域与非mask区域的结构信息,导致生成的图片语义连贯性较差。
  3. 这类方法只能实现object-level的编辑,无法实现图片风格、纹理的编辑。

在这篇文章中,作者提出了一种p2p的文字编辑方法(textual editing),无需训练任何参数、添加任何模块,仅用预训练的文生图模型(如stable diffusion)即能实现卓越的textual editing能力。下图展示了引入p2p技术后,同样的随机种子和prompt的生成结果。

在这里插入图片描述

下面来看p2p具体是怎么做的吧。

3 方法

3.1 什么是prompt-to-prompt 🤔

通过上面的背景和动机介绍,我们知道p2p做的是这样一件事:

给定原始图片的prompt( P \mathcal{P} P)与编辑图片的prompt ( P ∗ \mathcal{P}^* P),通过文生图模型,分别获得原始图片 I \mathcal{I} I与编辑后的图片 I ∗ \mathcal{I}^* I I \mathcal{I} I I ∗ \mathcal{I}^* I除了编辑区域外尽可能的近。

举个🌰,当我输入prompt a photo of a house on a mountain.用文生图生成了一张在山上的房子的图片,现在我们想维持生成图片的整体布局,仅将其改为冬景。用p2p技术可以很方便实现,如下图所示

在这里插入图片描述

3.2 prompt-to-prompt的具体实现 🤔

在详细介绍p2p之前,我们先来回答motivation中的一个问题。

为什么给定了随机种子,仅微小的改变prompt,输出的图片却差异很大?

我们知道在文生图中,prompt与diffusion model是在cross-attention层进行交互(text embedding作为cross-attention的key和value)。如下图所示(灰色的块代表mask)。

在这里插入图片描述

📌忘记文生图条件融合的话,可以回顾 classifier-free guided的内容。

假定当prompt的第二个token发生改变时,根据下图的计算流,可以看到整个attention score的数值都会发生改变。从而导致最终输出结果发生改变。

在这里插入图片描述

3.2.1 cross-attention对生成图片的影响

通过对diffusion model网络内部的观察,作者发现生成图片的空间布局和几何形状都是由内部的cross-attention层的attention map决定(上图的 a t t e n \mathrm{atten} atten)。下图是由prompt: “a furry bear watching a bird”生成的图片,我们分别看每一个token对应的attention map对应生成图片的相应位置。并在time step的早期这个对应关系就已形成。

在这里插入图片描述

在这里插入图片描述

这里提供一张attention map随时间步变化的gif图。

在这里插入图片描述

3.2.1 controlling the cross-attention

control的思路很简单。既然cross-attention的attention map决定生成图片的结构信息,那我们维持原始的attention map即可。

p2p的整体算法流程如下图所示

每一个时间步 t t t分别计算原始prompt P \mathcal{P} P的attention map M t M_t Mt和新的prompt P ∗ \mathcal{P}^* P的attention map M t ∗ M^*_t Mt并用特定的替换规则 E d i t ( M t , M t ∗ , t ) Edit(M_t, M_t^*, t) Edit(Mt,Mt,t)替换后再进行生成。

在这里插入图片描述

作者根据不同的编辑类型,设计了不同的替换方式

在这里插入图片描述

(一)Word Swap

这个编辑类型是指将原始prompt中的某个token用新的token进行替换。 P = \mathcal{P} = P= “photo of a cat riding on a bicycle”, P ∗ = \mathcal{P}^* = P= “photo of a cat riding on a motorcycle”。此时的替换规则是

E d i t ( M t , M t ∗ , t ) : = { M t ∗ i f   t < τ M t o t h e r w i s e . (1) E d i t ( M _ { t } , M _ { t } ^ { * } , t ) : = \left\{ \begin{array} { c l } { M _ { t } ^ { * } } & { \quad \mathrm { i f \ } t \lt \tau } \\ { M _ { t } } & { \quad \mathrm { o t h e r w i s e . } } \\ \end{array} \right . \tag{1} Edit(Mt,Mt,t):={MtMtif t<τotherwise.(1)

τ \tau τ表示某一时间步。当时间步小于 τ \tau τ时不做替换,否则用原始prompt的attention map做替换。(当两个词的长度不同时,可以对少的进行复制)引入 τ \tau τ的目的是:有一些编辑对图像的几何改变会很大,可以通过引入控制时机 τ \tau τ来缓和。Word Swap的编辑形式可以很方便的对图片中某个物体进行局部编辑。

在这里插入图片描述

(二)Adding a New Phrase

指的是在原始prompt P \mathcal{P} P新增一些token。如 P = \mathcal{P}= P= “a photo of a house on a mountain”, P ∗ = \mathcal{P}^* = P= “a photo of a house on a mountain at winter”。

( E d i t ( M t , M t ∗ , t ) ) i , j : = { ( M t ∗ ) i , j i f   A ( j ) = N o n e ( M t ) i , A ( j ) o t h e r w i s e . (2) ( E d i t ( M _ { t } , M _ { t } ^ { * } , t ) ) _ { i , j } : = \left \{ \begin{array} { l l } { { ( M _ { t } ^ { * } ) _ { i , j } } } & { { \mathrm { i f } \ A ( j ) = N o n e } } \\ { { ( M _ { t } ) _ { i , A ( j ) } } } & { { \mathrm { o t h e r w i s e } . } } \end{array} \right . \tag{2} (Edit(Mt,Mt,t))i,j:={(Mt)i,j(Mt)i,A(j)if A(j)=Noneotherwise.(2)

i i i 表示visual token的索引位置, j j j 表示 P ∗ \mathcal{P}^* P中text token 的索引位置; A ( j ) A(j) A(j)表示, P ∗ \mathcal{P}^* P的text token j j j P \mathcal{P} P中的索引位置。这种类型的control同样可以引入word swap中的 τ \tau τ来控制control的时机。用这个方法可以对图像进行全局的编辑,如下面例子的改变风格整体图片的风格为“winter”。

在这里插入图片描述

(三)Attention Re–weighting

基于p2p还可以精细的控制prompt每一个token的控制强度。这个场景 P \mathcal{P} P P ∗ \mathcal{P}^* P是相同的,可以更改特定token的权重来控制图像。

( E d i t ( M t , M t ∗ , t ) ) i , j : = { c ⋅ ( M t ) i , j i f   j = j ∗ ( M t ) i , j o f h e r w i s e . (3) ( E d i t ( M _ { t } , M _ { t } ^ { * } , t ) ) _ { i , j } : = \left \{ \begin{array} { c c } { c \cdot ( M _ { t } ) _ { i , j } } & { \mathrm { i f } \ j = j ^ { * } } \\ { ( M _ { t } ) _ { i , j } } & { \mathrm { o f h e r w i s e } . } \\ \end{array} \right . \tag{3} (Edit(Mt,Mt,t))i,j:={c(Mt)i,j(Mt)i,jif j=jofherwise.(3)
在这里插入图片描述

4 核心部分代码说明

diffusers.version == 0.10.0

4.1 修改cross-attention层的forward

p2p的核心是修改cross-attention层的计算方式,为此我们需要重写diffusers内部cross-attention的forward函数,引入controller.control() 来控制attention map的编辑。

def control_cross_attn_forward(self, controller: BaseController, place_in_unet):
    def forward(x, context: Optional[torch.Tensor] = None, mask: Optional[torch.Tensor] = None):
        batch_size, sequence_length, dim = x.shape
        h = self.heads
        q = self.to_q(x)
        is_cross = context is not None
        context = context if is_cross else x
        k = self.to_k(context)
        v = self.to_v(context)
        q = self.reshape_heads_to_batch_dim(q)
        k = self.reshape_heads_to_batch_dim(k)
        v = self.reshape_heads_to_batch_dim(v)

        sim = torch.einsum("b i d, b j d -> b i j", q, k) * self.scale

        if mask is not None:
            mask = mask.reshape(batch_size, -1)
            max_neg_value = -torch.finfo(sim.dtype).max
            mask = mask[:, None, :].repeat(h, 1, 1)
            sim.masked_fill_(~mask, max_neg_value)

        # attention, what we cannot get enough of
        attn = sim.softmax(dim=-1)
        # print(f"attn shape: {attn.shape}")
        attn = controller.control(attn, is_cross, place_in_unet)  # AttentionStore时相当于将attention值缓存到controller中
        out = torch.einsum("b i j, b j d -> b i d", attn, v)
        out = self.reshape_batch_dim_to_heads(out)
        to_out = self.to_out
        if type(to_out) is torch.nn.modules.container.ModuleList:
            to_out = self.to_out[0]  # 忽略dropout
        else:
            to_out = self.to_out
        return to_out(out)
    return forward

def register_attention_control_mine(unet, controller):
    cross_attn_name_ls = []
    for i in unet.named_children():
        name, cur_module = i[:2]
        if cur_module.__class__.__name__ == "CrossAttention":
            cur_module.forward = control_cross_attn_forward(cur_module, controller, name)
            cross_attn_name_ls.append(name)
        elif hasattr(cur_module, "children"):
            module_ls = [(name, cur_module)]
            while module_ls:
                name, cur_module = module_ls.pop()
                for sub_name, sub_module in cur_module.named_children():
                    if sub_module.__class__.__name__ == "CrossAttention":
                        sub_module.forward = control_cross_attn_forward(
                            sub_module,
                            controller,
                            f"{name}.{sub_name}"
                        )
                        cross_attn_name_ls.append(f"{name}.{sub_name}")
                    elif hasattr(sub_module, "children"):
                        module_ls.append((f"{name}.{sub_name}", sub_module))
    controller.num_att_layers = len(cross_attn_name_ls)
    controller.cross_attn_name_ls = cross_attn_name_ls

4.2 control attention map

controller.control() 内部的实现方式

class EditControllerMemEfficient(BaseController):
    def __init__(
            self, edit_params: EditParams,
            max_vis_pixel_num=MAX_VIS_PIXEL_NUM,
            cached_attn_info_flag=False,
            logger=base_logger
    ):
        super(EditControllerMemEfficient, self).__init__(
            max_vis_pixel_num=max_vis_pixel_num, 
            cached_attn_info_flag=cached_attn_info_flag, edit_params=edit_params, logger=logger)
        self.control_info_checking()

    def cross_attn_control(self, attn: torch.Tensor, place_in_unet: str) -> torch.Tensor:
        assert attn.shape[0] > 1, f"attn shape: {attn.shape}"
        source_replace_mask = self.replace_index_map["source_mask"]
        target_replace_mask = self.replace_index_map["target_mask"]
        source_token_weight = self.replace_index_map["source_token_weight"]
        target_token_weight = self.replace_index_map["target_token_weight"]

        if self.do_cross_attn_control_flag:
            attn = rearrange(attn, "(b h) p c -> b h p c", b=self.batch_size)
            source_attn = attn[:1, ...]
            target_attn = attn[1:, ...]

            source_attn_for_merge = source_attn * source_token_weight
            target_attn = target_attn * target_token_weight
            target_attn[..., target_replace_mask] = source_attn_for_merge[..., source_replace_mask]
            attn = torch.cat([source_attn, target_attn], dim=0)

            attn = rearrange(attn, "b h p c -> (b h) p c")

        if self.do_local_blend and self.text_branch_flag:  # local blend whatever cross control
            blend_attn = attn
            self.set_blend_attn_map(place_in_unet, True, blend_attn)
        return attn
    
    def self_attn_control(self, attn: torch.Tensor, place_in_unet: str) -> torch.Tensor:
        if attn.shape[2] <= 16 ** 2:
            attn = rearrange(attn, "(b h) p c -> b h p c", b=self.batch_size)
            source_attn = attn[:1, ...]
            if self.do_self_attn_control_flag:
                attn = source_attn.expand(self.batch_size, *source_attn.shape[1:])
            attn = rearrange(attn, "b h p c -> (b h) p c")
        return attn
        
    def control(self, attn: torch.Tensor, is_cross: bool, place_in_unet: str) -> torch.Tensor:
        # print(f">>>cached_attn_flag: {self.cached_attn_info_flag}")
        assert self.current_step is not None, f"please set current time step by 'self.set_step'!"
        pixel_num = attn.shape[1]
        if pixel_num > self.max_vis_pixel_num:
            self.not_control_attn_name_set.add(place_in_unet)
            return attn
        if place_in_unet not in self.cached_attn.keys():
            self.cached_attn[place_in_unet] = dict() 

        if is_cross:
            attn = self.cross_attn_control(attn, place_in_unet)
        else:
            attn = self.self_attn_control(attn, place_in_unet)

        if self.cached_attn_info_flag:
            self.cached_attn_name_set.add(place_in_unet)
            if is_cross and self.do_cross_attn_control_flag:
                self.set_cached_attn(place_in_unet, is_cross, attn)
            elif is_cross and not self.do_cross_attn_control_flag:
                self.set_cached_attn(place_in_unet, is_cross, None)
            elif not is_cross and self.do_self_attn_control_flag:
                self.set_cached_attn(place_in_unet, is_cross, attn)
            else:
                self.set_cached_attn(place_in_unet, is_cross, None)
        return attn

4.3 支持的编辑方式

代码中通过EditParams类来指定编辑的参数

class EditParams:
    source_prompt: str
    target_prompt: str
    cross_merge_end_step: Union[float, int]  # cross attention merge step, 0-(cross_merge_step * diffusion step)  using cross-attn injection 
    self_merge_end_step: Union[float, int]  # self attention merge step, 0-(self_merge_step * diffusion step) using self-attn injection
    cross_merge_start_step: Union[float, int] = 0  # cross attention merge step, 0-(cross_merge_step * diffusion step)  using cross-attn injection
    self_merge_start_step: Union[float, int] = 0  # self attention merge step, 0-(self_merge_step * diffusion step) using self-attn injection
    addition_token_control_info: Optional[Dict] = None
    do_noise_branch_control: bool = False
    do_local_blend: bool = False  # using local blend
    blend_focus_text: Optional[List] = None

5 One More Thing

5.1 p2p with additional constraints

的edit能力通过引入以下3个约束还能进一步提升

  • self attention的约束

将原始图片在self attention处的attention map迁移给编辑图片,非编辑区域维持性会更强。详细可见pnp[7]论文。

下图展现了当使用self- attention control时的编辑效果。应用的步长越多,非edit区域的维持性越好。

source prompt: "a photo of a house on a mountain.”

target_prompt: "a photo of a house on a mountain at winter"

在这里插入图片描述

同样,有一些编辑对图像的几何改变会很大,不宜控制过多

在这里插入图片描述

  • 引入local blend

仅更改需要编辑区域的pixel,保留其它区域的pixel。编辑区域的mask为token对应的attention map。底层原理可见repaint[8] paper。

如:当引入“mountain”的local blend限制时,只有山的区域变为雪景。

在这里插入图片描述

当local-blend还可以结合re-weight等编辑策略,可以实现更细粒度的控制

在这里插入图片描述

  • noise分支引入self attention的约束

我们知道对于classifier-free的文生图,需要同时计算条件分支的噪声估计 ϵ θ ( x t , y , t ) \epsilon_{\theta}(x_t, y, t) ϵθ(xt,y,t)和非条件分支的噪声估计 ϵ θ ( x t , y = ∅ , t ) \epsilon_{\theta}(x_t, y=\empty, t) ϵθ(xt,y=,t) ,再通过classifier-free的方式融合。尝试发现,非条件分支引入self-attention control有助于进一步提升编辑效果(相比前面,提升不太大)。

ϵ ^ θ ( x t , y , t ) = ϵ θ ( x t , y = ∅ , t ) + s [ ϵ θ ( x t , y , t ) − ϵ θ ( x t , y = ∅ , t ) ] (4) \begin{align} \hat{\epsilon}_{\theta}(x_t, y, t)=\epsilon_{\theta}(x_t, y=\empty,t) + s[\epsilon_{\theta}(x_t, y, t) - \epsilon_{\theta}(x_t, y=\empty, t) ] \end{align} \tag{4} ϵ^θ(xt,y,t)=ϵθ(xt,y=,t)+s[ϵθ(xt,y,t)ϵθ(xt,y=,t)](4)

5.2 p2p for real image editing

若要采用p2p论文中的方法进行编辑需要知道两个信息:1)图片的初始噪声分布;2)图片的prompt。如果直接拿一张图过来是没有办法进行p2p进行编辑的。需要先得到以下两个信息:

1)给定或生成这张图的prompt;

2)估计出给定prompt下这张图的噪声。

在作者后续的Null-text Inversion [9]工作中对这类情形进一步研究,后续文章中将详细介绍。

参考文献

[1] InstructPix2Pix: Learning to Follow Image Editing Instructions

[2] Emu Edit: Precise Image Editing via Recognition and Generation Tasks

[3] RePaint: Inpainting using Denoising Diffusion Probabilistic Models

[4] DiffEdit: Diffusion-based semantic image editing with mask guidance

[5] Segment Anything

[6] classifier-free diffusion model

[7] Plug-and-Play Diffusion Features for Text-Driven Image-to-Image Translation

[8] RePaint: Inpainting using Denoising Diffusion Probabilistic Models

[9] Null-text Inversion for Editing Real Images using Guided Diffusion Models

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1537225.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【OpenSSH】Windows系统使用OpenSSH搭建SFTP服务器

【OpenSSH】Windows系统使用OpenSSH搭建SFTP服务器 文章目录 【OpenSSH】Windows系统使用OpenSSH搭建SFTP服务器一、环境说明二、安装配置步骤1.下载完成后&#xff0c;传至服务器或者本机并解压至C:/Program Files/目录下2.打开PowerShell终端3.进入到包含ssh可执行exe文件的文…

线性顺序表算法库

list.cpp 具体函数实现 #include <stdio.h> #include "list.h" #include <malloc.h>/************************************************** ①函数名: CreateList 功 能: 用数组构建顺序表 参 数: ①SqList *&L:传入的线性表 ②ElemType a[]:使用…

网络安全是什么? 为什么要学网络安全 ?网络安全怎么学习?

网络安全是什么&#xff1f; 网络安全是指保护计算机网络、网络设备、应用程序、数据和用户免受非法访问、攻击、破坏或泄漏的过程和技术。网络安全包括多个领域&#xff0c;例如网络防御、漏洞管理、加密技术、身份验证和访问控制等等。 网络安全非常重要&#xff0c;因为现…

【Java反序列化】CommonsCollections-CC1链分析

前言 好几天没发博文了&#xff0c;偷偷憋了个大的——CC1链分析&#xff0c;手撸了一遍代码。虽然说&#xff0c;这个链很老了&#xff0c;但还是花费了我一段时间去消化吸收&#xff0c;那么接下来&#xff0c;我会简洁的介绍下整个链的利用过程&#xff0c;还有哪些不理解的…

命令提示符——CMD基础操作介绍

&#x1f49e;&#x1f49e; 前言 hello hello~ &#xff0c;这里是大耳朵土土垚~&#x1f496;&#x1f496; &#xff0c;欢迎大家点赞&#x1f973;&#x1f973;关注&#x1f4a5;&#x1f4a5;收藏&#x1f339;&#x1f339;&#x1f339; &#x1f4a5;个人主页&#x…

【MySQL】基本查询(1)

【MySQL】基本查询&#xff08;1&#xff09; 目录 【MySQL】基本查询&#xff08;1&#xff09;表的增删改查Create单行数据 全列插入多行数据 指定列插入插入否则更新替换 RetrieveSELECT 列全列查询指定列查询查询字段为表达式为查询结果指定别名结果去重 WHERE 条件英语不…

学点儿Java_Day9_多图带你搞懂Java访问修饰符

1 前言 在学习Java访问修饰符的作用及相应的效果时&#xff0c;看到了像下面这样的图 表达的内容基本都是一致的&#xff0c;但是带着一些疑惑经过一番“深入”学习后&#xff0c;我觉得这样划分不够细致&#xff0c;把我的总结分享一下。 2 多图带你搞懂Java访问修饰符 …

[环境配置].ssh文件夹权限修改方法

问题描述&#xff1a; 通过VSCode中的Remote Explorer或者通过CMD等命令行窗口连接远程机器时&#xff0c;会因为提示 "Bad owner or permissions on C:\\Users\\xxx/.ssh/config"而导致失败&#xff0c;最终呈现在VSCode中的效果是&#xff0c;弹窗提示"Could…

数据挖掘与机器学习 1. 绪论

于高山之巅&#xff0c;方见大河奔涌&#xff1b;于群峰之上&#xff0c;便觉长风浩荡 —— 24.3.22 一、数据挖掘和机器学习的定义 1.数据挖掘的狭义定义 背景&#xff1a;大数据时代——知识贫乏 数据挖掘的狭义定义&#xff1a; 数据挖掘就是从大量的、不完全的、有噪声的、…

OceanPen Art AI绘画系统 运营教程(二)AI视频AI创作PPT

在一个崇高的目标支持下&#xff0c;不停地工作&#xff0c;即使慢&#xff0c;也一定会获得成功。 —— 爱因斯坦 演示站点&#xff1a; ai.oceanpen.art 官方论坛&#xff1a; www.jingyuai.com 登陆后台 ppt密匙设置 导航菜单配置 Key池管理 二、前端显示 体验站点…

Mysql---DML

文章目录 前言一、pandas是什么&#xff1f;二、使用步骤 1.引入库2.读入数据总结 一.DML概述 DML&#xff08;Data Manipulation Language&#xff09;是MySQL中用于操作数据库中数据的语言。DML语句用于插入、更新和删除数据库中的记录&#xff0c;以及查询和修改数据库中的数…

Redisson分布式锁(WatchDog分析,浅浅看下源码)

带大家简单了解下Redisson的看门狗机制&#xff0c;这个面试中也比较常见。 目录 WatchDog&#xff08;看门狗&#xff09;机制开启WatchDog&#xff08;看门狗&#xff09;浅看下源码 WatchDog&#xff08;看门狗&#xff09;机制 Redisson看门狗机制是用于解决在业务运行时间…

WSL2的安装步骤

WSL2&#xff08;Windows Subsystem for Linux 2&#xff09;是微软公司开发的一项创新性技术&#xff0c;它在Windows操作系统上提供了一个完整的Linux内核&#xff0c;并允许用户在Windows环境中运行Linux发行版。之前想在Windows上使用Linux系统必须先安装VirtualBox或VMWar…

PTA 抢红包 25分 (JAVA)

题目描述 没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录&#xff0c;请你统计一下他们抢红包的收获。 输入格式&#xff1a; 输出格式&#xff1a; 按照收入金额从高到低的递减顺序输出每个人的编号和收入金额&#xff08;以元为单位&#xff0c;输出小…

JsonUtility.ToJson 和UnityWebRequest 踩过的坑记录

项目场景&#xff1a; 需求&#xff1a;我在做网络接口链接&#xff0c;使用的unity自带的 UnityWebRequest &#xff0c;数据传输使用的json&#xff0c;json和自定义数据转化使用的也是unity自带的JsonUtility。使用过程中发现两个bug。 1.安全验证失败。 报错为&#xff1a…

day-24 跳跃游戏 III

思路&#xff1a;dfs方法&#xff0c;从开始节点开始进行深度优先遍历&#xff0c;利用一个数组vis[]记录该位置是否被访问过&#xff0c;如果遍历到一个已经访问的位置&#xff0c;返回false 如果遍历到某位置的值为0&#xff0c;返回true code: class Solution {public boo…

006_【基础篇】springboot整合Mybatis

SpringBoot 整合 Mybatis 只需要两步&#xff1a; 案例&#xff1a; 创建数据库 在 IDEA 提供的插件的内置的数据库图形化界面(其他图形化界面软件也可以&#xff0c;都一样&#xff09; 中创建以下数据库&#xff1a; create database if not exists mybatis;use mybatis…

类于对象(上)--- 类的定义、访问限定符、计算类和对象的大小、this指针

在本篇中将会介绍一个很重要和很基础的Cpp知识——类和对象。对于类和对象的篇目将会有三篇&#xff0c;本篇是基础篇&#xff0c;将会介绍类的定义、类的访问限定符符和封装、计算类和对象的大小、以及类的 this 指针。目录如下&#xff1a; 目录 1. 关于类 1.1 类的定义 2 类…

Spring Boot项目中使用MyBatis连接达梦数据库6

在开发中&#xff0c;使用Spring Boot框架结合MyBatis来操作数据库是一种常见的做法。本篇博客将介绍如何在Spring Boot项目中配置MyBatis来连接达梦数据库6&#xff0c;并提供一个简单的示例供参考。(达梦六不仅分表还分模式.) 我拿SYSTEM表的LPS模式下面Student表做案例。 1.…

AI系统性学习—LangChain入门

文章目录 1、LangChain入门1.1 简介1.2 架构1.3 核心概念1.2 快速入门1.3 安装 2、LangChain Prompt Template2.1 什么是提示词模版2.1 创建一个提示词模版2.2 聊天消息提示词模版2.3 模版追加示例 3、语言模型3.1 LLM基础模型3.2 LangChain聊天模型3.3 自定义模型3.4 输出解析…