当前位置: 首页 > news >正文

使用 PYTORCH 进行图像风格迁移

一、介绍

        本教程介绍如何实现 由 Leon A. Gatys、Alexander S. Ecker 和 Matthias Bethge 开发的神经风格算法。神经风格或神经传输允许您拍摄图像并以新的艺术风格再现它。该算法采用三幅图像,即输入图像、内容图像和风格图像,并将输入更改为类似于内容图像的内容和风格图像的艺术风格。

二、基本原则

        原理很简单:我们定义两个距离,一个距离为内容 (D_C) 和一个用于样式 ( D_S)。 D_C 测量两个图像之间内容的差异程度 D_S衡量两个图像之间的风格差异程度。然后,我们获取第三个图像(输入),并对其进行转换,以最小化其与内容图像的内容距离以及与样式图像的样式距离。现在我们可以导入必要的包并开始神经传输。

三、导入包并选择设备

        以下是实现神经传输所需的软件包列表。

  • torchtorch.nnnumpy(PyTorch 神经网络不可或缺的软件包)

  • torch.optim(高效梯度下降)

  • PILPIL.Imagematplotlib.pyplot(加载并显示图像)

  • torchvision.transforms(将PIL图像转换为张量)

  • torchvision.models(训练或加载预训练模型)

  • copy(深度复制模型;系统包)

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optimfrom PIL import Image
import matplotlib.pyplot as pltimport torchvision.transforms as transforms
import torchvision.models as modelsimport copy

        接下来,我们需要选择运行网络的设备并导入内容和样式图像。在大图像上运行神经传输算法需要更长的时间,并且在 GPU 上运行时速度会快得多。我们可以用来torch.cuda.is_available()检测是否有可用的 GPU。接下来,我们设置torch.device在整个教程中使用的 。该方法还.to(device) 用于将张量或模块移动到所需的设备。

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
torch.set_default_device(device)

四、加载图像

        现在我们将导入样式和内容图像。原始 PIL 图像的值在 0 到 255 之间,但当转换为 torch 张量时,它们的值将转换为 0 到 1 之间。图像还需要调整大小以具有相同的尺寸。需要注意的一个重要细节是,torch 库中的神经网络是使用 0 到 1 范围内的张量值进行训练的。如果您尝试向网络提供 0 到 255 个张量图像,那么激活的特征图将无法感知预期的特征内容和风格。然而,Caffe 库中的预训练网络是使用 0 到 255 个张量图像进行训练的。

注意

        以下是下载运行本教程所需图像的链接: picasso.jpg和 dance.jpg。images下载这两个图像并将它们添加到当前工作目录中的同名目录中。

# desired size of the output image
imsize = 512 if torch.cuda.is_available() else 128  # use small size if no GPUloader = transforms.Compose([transforms.Resize(imsize),  # scale imported imagetransforms.ToTensor()])  # transform it into a torch tensordef image_loader(image_name):image = Image.open(image_name)# fake batch dimension required to fit network's input dimensionsimage = loader(image).unsqueeze(0)return image.to(device, torch.float)style_img = image_loader("./data/images/neural-style/picasso.jpg")
content_img = image_loader("./data/images/neural-style/dancing.jpg")assert style_img.size() == content_img.size(), \"we need to import style and content images of the same size"

        现在,让我们创建一个函数,通过将图像的副本重新转换为 PIL 格式并使用 plt.imshow. 我们将尝试显示内容和样式图像,以确保它们正确导入。

unloader = transforms.ToPILImage()  # reconvert into PIL imageplt.ion()def imshow(tensor, title=None):image = tensor.cpu().clone()  # we clone the tensor to not do changes on itimage = image.squeeze(0)      # remove the fake batch dimensionimage = unloader(image)plt.imshow(image)if title is not None:plt.title(title)plt.pause(0.001) # pause a bit so that plots are updatedplt.figure()
imshow(style_img, title='Style Image')plt.figure()
imshow(content_img, title='Content Image')
  • 风格形象

  •  
  • 内容图片

五、损失函数

5.1 内容丢失

        内容损失是表示单个层的内容距离的加权版本的函数。该函数获取特征图F_{XL} 一层的 L在网络处理输入中 X并返回加权内容距离 w_{CL}\cdot D^L_C(X,C)  ​。 图像之间 X和内容图像 C。内容图像的特征图(F_{CL}) 必须由函数知道才能计算内容距离。我们将此函数实现为 torch 模块,其构造函数采用 F_{CL}  作为输入。距离\left \| F_{XL} - F_{CL} \right \| ^2  是两组特征图之间的均方误差,可以使用 计算nn.MSELoss

        我们将直接在用于计算内容距离的卷积层之后添加此内容损失模块。这样,每次向网络输入输入图像时,都会在所需的层计算内容损失,并且由于自动梯度,所有梯度都将被计算。现在,为了使内容损失层透明,我们必须定义一个forward方法来计算内容损失,然后返回该层的输入。计算出的损失被保存为模块的参数。

class ContentLoss(nn.Module):def __init__(self, target,):super(ContentLoss, self).__init__()# we 'detach' the target content from the tree used# to dynamically compute the gradient: this is a stated value,# not a variable. Otherwise the forward method of the criterion# will throw an error.self.target = target.detach()def forward(self, input):self.loss = F.mse_loss(input, self.target)return input

笔记

        重要细节:虽然这个模块被命名ContentLoss,但它不是真正的 PyTorch Loss 函数。如果要将内容损失定义为 PyTorch Loss 函数,则必须创建 PyTorch autograd 函数以在方法中手动重新计算/实现梯度backward 。

5.2 风格缺失

        风格丢失模块的实现与内容丢失模块类似。它将充当网络中的透明层,计算该层的风格损失。为了计算风格损失,我们需要计算 gram 矩阵 G_{XL} 。gram 矩阵是给定矩阵与其转置矩阵相乘的结果。在此应用中,给定矩阵是特征图的重塑版本  F_{XL}一层的 L。 F_{XL}  被重塑形成 \hat{F}_{XL} ,  K\times N 矩阵,其中 K是该L层的特征图的数量,另外N是任何矢量化特征图的长度F_{XL}^K 。例如,  \hat{F} _{XL} 的第一行对应于第一个向量化特征图 F_{XL}^1

        最后,必须通过将每个元素除以矩阵中的元素总数来对 gram 矩阵进行归一化。这种正常化是为了抵消以下事实:\hat{F} _{XL} 具有大的矩阵维度在 Gram 矩阵中产生更大的值。这些较大的值将导致第一层(池化层之前)在梯度下降期间产生更大的影响。风格特征往往位于网络的较深层,因此这个标准化步骤至关重要。

def gram_matrix(input):a, b, c, d = input.size()  # a=batch size(=1)# b=number of feature maps# (c,d)=dimensions of a f. map (N=c*d)features = input.view(a * b, c * d)  # resize F_XL into \hat F_XLG = torch.mm(features, features.t())  # compute the gram product# we 'normalize' the values of the gram matrix# by dividing by the number of element in each feature maps.return G.div(a * b * c * d)

        现在,风格丢失模块看起来几乎与内容丢失模块一模一样。风格距离也是使用之间的均方误差来计算的G_{XL} G_{SL}​​​​​​​ 

class StyleLoss(nn.Module):def __init__(self, target_feature):super(StyleLoss, self).__init__()self.target = gram_matrix(target_feature).detach()def forward(self, input):G = gram_matrix(input)self.loss = F.mse_loss(G, self.target)return input

六、导入模型

        现在我们需要导入一个预训练的神经网络。我们将使用 19 层 VGG 网络,就像论文中使用的那样。

        PyTorch 的 VGG 实现是一个模块,分为两个子 Sequential模块:(features包含卷积层和池化层)和classifier(包含全连接层)。我们将使用该 features模块,因为我们需要各个卷积层的输出来测量内容和风格损失。有些层在训练期间的行为与评估期间的行为不同,因此我们必须使用 将网络设置为评估模式.eval()

cnn = models.vgg19(pretrained=True).features.eval()
/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning:The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead./opt/conda/envs/py_3.10/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning:Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=VGG19_Weights.IMAGENET1K_V1`. You can also use `weights=VGG19_Weights.DEFAULT` to get the most up-to-date weights.Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to /var/lib/jenkins/.cache/torch/hub/checkpoints/vgg19-dcbb9e9d.pth0%|          | 0.00/548M [00:00<?, ?B/s]2%|2         | 12.1M/548M [00:00<00:04, 126MB/s]4%|4         | 24.4M/548M [00:00<00:04, 128MB/s]7%|6         | 36.7M/548M [00:00<00:04, 129MB/s]9%|8         | 49.1M/548M [00:00<00:04, 129MB/s]11%|#1        | 61.5M/548M [00:00<00:03, 130MB/s]13%|#3        | 74.0M/548M [00:00<00:03, 130MB/s]16%|#5        | 86.5M/548M [00:00<00:03, 130MB/s]18%|#8        | 98.9M/548M [00:00<00:03, 130MB/s]20%|##        | 111M/548M [00:00<00:03, 130MB/s]23%|##2       | 124M/548M [00:01<00:03, 130MB/s]25%|##4       | 136M/548M [00:01<00:03, 130MB/s]27%|##7       | 149M/548M [00:01<00:03, 130MB/s]29%|##9       | 161M/548M [00:01<00:03, 130MB/s]32%|###1      | 173M/548M [00:01<00:03, 130MB/s]34%|###3      | 186M/548M [00:01<00:02, 130MB/s]36%|###6      | 198M/548M [00:01<00:02, 130MB/s]38%|###8      | 211M/548M [00:01<00:02, 130MB/s]41%|####      | 223M/548M [00:01<00:02, 129MB/s]43%|####2     | 235M/548M [00:01<00:02, 129MB/s]45%|####5     | 248M/548M [00:02<00:02, 130MB/s]47%|####7     | 260M/548M [00:02<00:02, 129MB/s]50%|####9     | 272M/548M [00:02<00:02, 130MB/s]52%|#####1    | 285M/548M [00:02<00:02, 130MB/s]54%|#####4    | 297M/548M [00:02<00:02, 130MB/s]57%|#####6    | 310M/548M [00:02<00:01, 130MB/s]59%|#####8    | 322M/548M [00:02<00:01, 130MB/s]61%|######1   | 335M/548M [00:02<00:01, 130MB/s]63%|######3   | 347M/548M [00:02<00:01, 130MB/s]66%|######5   | 359M/548M [00:02<00:01, 130MB/s]68%|######7   | 372M/548M [00:03<00:01, 130MB/s]70%|#######   | 384M/548M [00:03<00:01, 130MB/s]72%|#######2  | 397M/548M [00:03<00:01, 130MB/s]75%|#######4  | 409M/548M [00:03<00:01, 130MB/s]77%|#######6  | 422M/548M [00:03<00:01, 130MB/s]79%|#######9  | 434M/548M [00:03<00:00, 129MB/s]81%|########1 | 446M/548M [00:03<00:00, 130MB/s]84%|########3 | 459M/548M [00:03<00:00, 129MB/s]86%|########5 | 471M/548M [00:03<00:00, 130MB/s]88%|########8 | 484M/548M [00:03<00:00, 130MB/s]91%|######### | 496M/548M [00:04<00:00, 130MB/s]93%|#########2| 508M/548M [00:04<00:00, 130MB/s]95%|#########5| 521M/548M [00:04<00:00, 130MB/s]97%|#########7| 533M/548M [00:04<00:00, 130MB/s]
100%|#########9| 546M/548M [00:04<00:00, 130MB/s]
100%|##########| 548M/548M [00:04<00:00, 130MB/s]

        此外,VGG 网络在图像上进行训练,每个通道均按平均值=[0.485,0.456,0.406]和标准差=[0.229,0.224,0.225]标准化。在将图像发送到网络之前,我们将使用它们来标准化图像。

cnn_normalization_mean = torch.tensor([0.485, 0.456, 0.406])
cnn_normalization_std = torch.tensor([0.229, 0.224, 0.225])# create a module to normalize input image so we can easily put it in a
# ``nn.Sequential``
class Normalization(nn.Module):def __init__(self, mean, std):super(Normalization, self).__init__()# .view the mean and std to make them [C x 1 x 1] so that they can# directly work with image Tensor of shape [B x C x H x W].# B is batch size. C is number of channels. H is height and W is width.self.mean = torch.tensor(mean).view(-1, 1, 1)self.std = torch.tensor(std).view(-1, 1, 1)def forward(self, img):# normalize ``img``return (img - self.mean) / self.std

        顺序模块包含子模块的有序列表。例如,vgg19.features 包含一个按正确深度顺序对齐的序列(Conv2d、ReLU、MaxPool2d、Conv2d、ReLU...)。我们需要在它们正在检测的卷积层之后立即添加内容损失和风格损失层。为此,我们必须创建一个新的 Sequential 模块,其中正确插入了内容丢失和样式丢失模块。

# desired depth layers to compute style/content losses :
content_layers_default = ['conv_4']
style_layers_default = ['conv_1', 'conv_2', 'conv_3', 'conv_4', 'conv_5']def get_style_model_and_losses(cnn, normalization_mean, normalization_std,style_img, content_img,content_layers=content_layers_default,style_layers=style_layers_default):# normalization modulenormalization = Normalization(normalization_mean, normalization_std)# just in order to have an iterable access to or list of content/style# lossescontent_losses = []style_losses = []# assuming that ``cnn`` is a ``nn.Sequential``, so we make a new ``nn.Sequential``# to put in modules that are supposed to be activated sequentiallymodel = nn.Sequential(normalization)i = 0  # increment every time we see a convfor layer in cnn.children():if isinstance(layer, nn.Conv2d):i += 1name = 'conv_{}'.format(i)elif isinstance(layer, nn.ReLU):name = 'relu_{}'.format(i)# The in-place version doesn't play very nicely with the ``ContentLoss``# and ``StyleLoss`` we insert below. So we replace with out-of-place# ones here.layer = nn.ReLU(inplace=False)elif isinstance(layer, nn.MaxPool2d):name = 'pool_{}'.format(i)elif isinstance(layer, nn.BatchNorm2d):name = 'bn_{}'.format(i)else:raise RuntimeError('Unrecognized layer: {}'.format(layer.__class__.__name__))model.add_module(name, layer)if name in content_layers:# add content loss:target = model(content_img).detach()content_loss = ContentLoss(target)model.add_module("content_loss_{}".format(i), content_loss)content_losses.append(content_loss)if name in style_layers:# add style loss:target_feature = model(style_img).detach()style_loss = StyleLoss(target_feature)model.add_module("style_loss_{}".format(i), style_loss)style_losses.append(style_loss)# now we trim off the layers after the last content and style lossesfor i in range(len(model) - 1, -1, -1):if isinstance(model[i], ContentLoss) or isinstance(model[i], StyleLoss):breakmodel = model[:(i + 1)]return model, style_losses, content_losses

接下来,我们选择输入图像。您可以使用内容图像的副本或白噪声。

input_img = content_img.clone()
# if you want to use white noise by using the following code:
#
# ::
#
# input_img = torch.randn(content_img.data.size())# add the original input image to the figure:
plt.figure()
imshow(input_img, title='Input Image')

输入图像

七、梯度下降

        正如该算法的作者 Leon Gatys 所建议的,我们将使用 L-BFGS 算法来运行梯度下降。与训练网络不同,我们希望训练输入图像以最小化内容/风格损失。我们将创建一个 PyTorch L-BFGS 优化器optim.LBFGS,并将图像传递给它作为要优化的张量。

def get_input_optimizer(input_img):# this line to show that input is a parameter that requires a gradientoptimizer = optim.LBFGS([input_img])return optimizer

        最后,我们必须定义一个执行神经传输的函数。对于网络的每次迭代,它都会收到更新的输入并计算新的损失。我们将运行backward每个损失模块的方法来动态计算它们的梯度。优化器需要一个“闭包”函数,它重新评估模块并返回损失。

        我们还有最后一个限制需要解决。网络可能会尝试使用超过图像 0 到 1 张量范围的值来优化输入。我们可以通过每次网络运行时将输入值纠正为 0 到 1 之间来解决这个问题。

def run_style_transfer(cnn, normalization_mean, normalization_std,content_img, style_img, input_img, num_steps=300,style_weight=1000000, content_weight=1):"""Run the style transfer."""print('Building the style transfer model..')model, style_losses, content_losses = get_style_model_and_losses(cnn,normalization_mean, normalization_std, style_img, content_img)# We want to optimize the input and not the model parameters so we# update all the requires_grad fields accordinglyinput_img.requires_grad_(True)# We also put the model in evaluation mode, so that specific layers# such as dropout or batch normalization layers behave correctly.model.eval()model.requires_grad_(False)optimizer = get_input_optimizer(input_img)print('Optimizing..')run = [0]while run[0] <= num_steps:def closure():# correct the values of updated input imagewith torch.no_grad():input_img.clamp_(0, 1)optimizer.zero_grad()model(input_img)style_score = 0content_score = 0for sl in style_losses:style_score += sl.lossfor cl in content_losses:content_score += cl.lossstyle_score *= style_weightcontent_score *= content_weightloss = style_score + content_scoreloss.backward()run[0] += 1if run[0] % 50 == 0:print("run {}:".format(run))print('Style Loss : {:4f} Content Loss: {:4f}'.format(style_score.item(), content_score.item()))print()return style_score + content_scoreoptimizer.step(closure)# a last correction...with torch.no_grad():input_img.clamp_(0, 1)return input_img

最后,我们可以运行算法。

output = run_style_transfer(cnn, cnn_normalization_mean, cnn_normalization_std,content_img, style_img, input_img)plt.figure()
imshow(output, title='Output Image')# sphinx_gallery_thumbnail_number = 4
plt.ioff()
plt.show()

Building the style transfer model..
/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/utils/_device.py:77: UserWarning:To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).Optimizing..
run [50]:
Style Loss : 4.124115 Content Loss: 4.153235run [100]:
Style Loss : 1.121803 Content Loss: 3.012928run [150]:
Style Loss : 0.696039 Content Loss: 2.639936run [200]:
Style Loss : 0.469292 Content Loss: 2.485867run [250]:
Style Loss : 0.341620 Content Loss: 2.400899run [300]:
Style Loss : 0.263747 Content Loss: 2.347282

脚本总运行时间:(0分38.249秒)

参考资料:

Neural Transfer Using PyTorch — PyTorch Tutorials 2.1.0+cu121 documentation

相关文章:

使用 PYTORCH 进行图像风格迁移

一、介绍 本教程介绍如何实现 由 Leon A. Gatys、Alexander S. Ecker 和 Matthias Bethge 开发的神经风格算法。神经风格或神经传输允许您拍摄图像并以新的艺术风格再现它。该算法采用三幅图像&#xff0c;即输入图像、内容图像和风格图像&#xff0c;并将输入更改为类似于内容…...

vscode使用flake8设置单行最长字符限制设置失败的问题

vscode使用flake8设置单行最长字符限制设置失败的问题 问题描述解决方案 问题描述 如图所示&#xff0c;使用flake8单行字数过长&#xff0c;就会有有红色底的波浪线 一般情况下很多教程都会让你在setting.json里面设置 但是我打开我的setting.json&#xff0c;发现我已经进…...

SAP KO22内部订单预算BAPI与BDC

KO22可以为内部订单预先维护预算&#xff0c;以便在后续成本实际产生时进行控制。 使用BAPI进行创建&#xff1a;KBPP_EXTERN_UPDATE_CO SAP note 625613中对该BAPI的使用方式有详细介绍&#xff0c;使用时可进行参考。 年度预算&#xff1a;e_gjahr传值、e_ges置空&#xff…...

K8S篇之实现利用Prometheus监控pod的实时数据指标

一、监控部署 1、将k8s集群中kube-state-metrics指标进行收集&#xff0c;服务进行部署 1.1 pod性能指标&#xff08;k8s集群组件自动集成&#xff09; k8s组件本身提供组件自身运行的监控指标以及容器相关的监控指标。通过cAdvisor 是一个开源的分析容器资源使用率和性能特性的…...

智能巡检软件怎么选?企业设备管理需要做什么?

在当今竞争激烈的企业运营环境中&#xff0c;巡检管理的重要性不言而喻。然而&#xff0c;许多企业在执行巡检任务时面临着诸多挑战&#xff0c;如员工执行不到位、缺乏有效的人员监管、漏检误检、安全隐患以及数据整理困难等问题。这些问题如果不能得到妥善解决&#xff0c;不…...

【python】Django——连接mysql数据库

笔记为自我总结整理的学习笔记&#xff0c;若有错误欢迎指出哟~ 【Django专栏】 Django——django简介、django安装、创建项目、快速上手 Django——templates模板、静态文件、django模板语法、请求和响应 Django——连接mysql数据库 Django——连接mysql数据库 连接MySQL数据库…...

北京君正客户应用案例:掌静脉3D人脸猫眼视屏智能锁

凯迪仕在今年4月发布了智能锁旗舰新品K70 Pro Max掌静脉3D人脸猫眼视屏智能锁&#xff0c;随即这款新品也成了行业热议的焦点。凯迪仕每次新品都力求突破精益求精&#xff0c;不仅追求科技感、高级感与品质感&#xff0c;而且赋予科技温度&#xff0c;带来人文化的关怀。K70 Pr…...

人工智能+游戏 会带来什么

“人工智能游戏” 写在前面 随着人类生活水平的日益提高&#xff0c;游戏正在为越来越多的人们带去欢乐。同时&#xff0c;作为21世纪新兴科学技术的人工智能&#xff0c;也正在研究人员的努力下不断向前突破。那么&#xff0c;这两列高速前进的“火车”能否接轨并行呢&#…...

人工智能基础_机器学习030_ElasticNet弹性网络_弹性回归的使用---人工智能工作笔记0070

然后我们再来看elastic-net弹性网络,之所以叫弹性是因为,他融合了L1和L2正则,可以看到 他的公式 公式中有L1正则和L2正则两个都在这个公式中 可以看到弹性网络,在很多特征互相联系的时候,非常有用,比如, 相关性,如果数学好,那么物理也好,如果语文好,那么英语也好 这种联系 正…...

Python算法——平衡二叉树(AVL)

Python中的平衡二叉搜索树&#xff08;AVL树&#xff09;算法详解 平衡二叉搜索树&#xff08;AVL树&#xff09;是一种自平衡的二叉搜索树&#xff0c;它通过在插入或删除节点时进行旋转操作来保持树的平衡性。在AVL树中&#xff0c;任何节点的两个子树的高度差&#xff08;平…...

公开可用的API 合集

这是一个开源项目列表&#xff0c;收录了一些公开可用、无需注册或认证即可使用的API接口。 这个项目解决了开发者们在寻找合适的API时遇到的各种困难&#xff0c;如无法快速定位、难以筛选等问题&#xff0c;为他们提供了便捷的一站式查询服务。 项目是“public-apis”&…...

单片机编程原则

多任务编程的概念 方式一&#xff1a;实时操作系统&#xff08;不建议新手使用&#xff09; 方式二 &#xff1a;裸机多任务模型 逻辑多任务的基本原理 把三个任务分别分为一个一个的片段 然后先执行任务一的第一个切片 执行第二个任务的第一个片段 执行第三个任务的第一个片…...

开源短剧付费变现小程序源码系统+在线开通会员+在线充值 带完整的搭建教程

说起微短剧&#xff0c;相信大家都不会陌生。相比传统网剧冗长的剧情&#xff0c;微短剧最大的看点&#xff0c;是时长短、高浓缩&#xff0c;顺应了当下用户娱乐时间碎片化趋势。其故事题材多为赘婿、霸道总裁、穿越、重生等看似夸张、无厘头&#xff0c;但却非常“上头”的虚…...

基于Python机器学习、深度学习技术提升气象、海洋、水文领域实践应用能力

Python是功能强大、免费、开源&#xff0c;实现面向对象的编程语言&#xff0c;能够在不同操作系统和平台使用&#xff0c;简洁的语法和解释性语言使其成为理想的脚本语言。除了标准库&#xff0c;还有丰富的第三方库&#xff0c;Python在数据处理、科学计算、数学建模、数据挖…...

电商平台为什么需要及时部署ssl证书?

电商平台为什么需要及时部署ssl证书&#xff1f; 21世纪以来&#xff0c;互联网技术得到了快速的发展和应用上的普及&#xff0c;为生活、工作、学习都带来了巨大的变化。现代社会中&#xff0c;快节奏的生活让人们的购物方式也发生了极大的转变&#xff0c;逐渐由线下转为了线…...

卡码网语言基础课 | 12. 位置互换

通过本次练习&#xff0c;将要学习到以下C知识点&#xff1a; 位置互换交换变量字符串 题目&#xff1a;给定一个长度为偶数位的字符串&#xff0c;请编程实现字符串的奇偶位互换。 奇偶位互换是指字符串的奇数位和偶数位相互交换位置 即&#xff1a;第一位和第二位交换&…...

用DOM来读取XML时要注意的一些概念

2023年11月15日&#xff0c;周三下午 在 DOM&#xff08;文档对象模型&#xff09;中&#xff0c;有一些重要的概念和术语&#xff1a; 文档对象&#xff08;Document Object&#xff09;&#xff1a;表示整个 XML 文档的根节点&#xff0c;它是 DOM 树的入口点。元素节点&…...

openresty安装配置,执行shell脚本

下载并解压 OpenResty 源代码&#xff1a; bashCopy code wget https://openresty.org/download/openresty-1.19.9.1.tar.gz tar -zxvf openresty-1.19.9.1.tar.gz cd openresty-1.19.9.1 运行 ./configure 并指定安装路径&#xff1a; bashCopy code ./configure --prefix…...

解决Dockerfile中 Could not initialize class sun.awt.X11FontManager错误

Dockerfile中增加命令 RUN yum install dejavu-sans-fonts fontconfig -y如果您使用的是基于Alpine Linux的发行版&#xff0c;可以使用apk命令来安装DejaVu Sans字体和fontconfig工具 RUN apk update RUN apk add ttf-dejavu fontconfig...

Kubernetes(k8s)进阶

文章目录 Kubernetes进阶一、Namespace&#xff08;名称空间&#xff09;1.namespace介绍2.管理namespace查看namespace创建namespaceyaml文件配置namespace 二、Pod&#xff08;最小基本部署单元&#xff09;1.pod介绍2.管理pod创建并运行pod查看pod信息访问pod删除podyaml文件…...

[Vue 配置] Vite + Vue3 项目配置和使用 NProgress

文章归档&#xff1a;https://www.yuque.com/u27599042/coding_star/mfmsrf9tz98ox3qg 安装 pnpm i nprogress配置 NProgress 其他更多可参考&#xff0c;仓库地址&#xff1a;https://github.com/rstacruz/nprogress 在 src/config/nprogress.js 中进行配置 是否展示右上角圆…...

Android MQTT开发之 Hivemq MQTT Client

使用一个开源库&#xff1a;hivemq-mqtt-client&#xff0c;这是Java生态的一个MQTT客户端框架&#xff0c;需要Java 8&#xff0c;Android上使用的话问题不大&#xff0c;需要一些额外的配置&#xff0c;下面列出了相关的配置&#xff0c;尤其是 packagingOptions&#xff0c;…...

【Maven教程】(十一):使用 Maven 构建 Web应用 —— 使用 jetty-maven-plugin 进行测试、使用 Cargo 实现自动化部署~

Maven 使用 Maven 构建 Web应用 1️⃣ Web 项目的目录结构2️⃣ account-service2.1 account-service的 POM2.2 account-service 的主代码 3️⃣ account-web3.1 account-web 的POM3.2 account-web 的主代码 4️⃣ 使用 jetty-maven-plugin 进行测试5️⃣ 使用 Cargo 实现自动…...

番外 2 : LoadRunner 的安装以及配置

LoadRunner 的安装以及配置教程 一 . 配置 IE 浏览器二 . 安装 LoadRunner 工具三 . 修改默认浏览器的配置四 . 设置 LoadRunner 能够获取本地资源 Hello , 大家好 , 又给大家带来新的专栏喽 ~ 这个专栏是专门为零基础小白从 0 到 1 了解软件测试基础理论设计的 , 虽然还不足以…...

win10正确配置tensorRT环境

目的 使用tensorRT进行网络模型部署&#xff0c;加快推理速度 方法 安装tensorRT的过程需要对各种组件的版本进行匹配 前置安装套件有&#xff1a; 1、CUDA 2、cuDNN 3、pyCUDA 4、tensorflow或pytorch 主要记录tensorRT安装: tensorRT安装配置查询 步骤: 1、去tensorRT官网…...

C++初阶-模板初阶

模板初阶 一、泛型编程二、函数模板2.1函数模板概念2.2函数模板格式2.3函数模板的原理2.4函数模板的原理2.5模板参数的匹配原则 三、类模板3.1类模板的定义格式3.2类模板的实例化 一、泛型编程 如何实现一个通用的交换函数呢&#xff1f; void Swap(int& left, int& …...

基于Python实现汽车销售数据可视化【500010086】

导入模块 import numpy as np import pandas as pd import plotly.graph_objects as go import plotly.express as px获取数据 df1 pd.read_excel(r"./data/中国汽车总体销量.xlsx") print(df1.head(5))df1.info()df1[年份] df1[时间].dt.year df1[月份] df1[时…...

dist.init_process_group() 卡住超时导致报错

在跑模型是遇到一个问题&#xff1a; import torch.distributed as dist dist.init_process_group(backend"nccl", init_methodtcp://localhost:%d % tcp_port, ranklocal_rank, world_sizenum_gpus)程序卡在这一步一动不动。. 解决办法一&#xff1a; 我看网上有人…...

RESTFul API:真是让人又爱又恨

RESTFul API是一种广泛使用的Web服务设计风格&#xff0c;它以资源为中心&#xff0c;通过HTTP方法来操作这些资源。然而&#xff0c;尽管RESTFul架构风格在许多情况下都非常有用&#xff0c;但在实际应用中&#xff0c;我们也发现了一些不足之处。本文将详细阐述这些问题&…...

【洛谷 P1478】陶陶摘苹果(升级版)题解(多重集合+贪心算法)

陶陶摘苹果&#xff08;升级版&#xff09; 题目描述 又是一年秋季时&#xff0c;陶陶家的苹果树结了 n n n 个果子。陶陶又跑去摘苹果&#xff0c;这次他有一个 a a a 公分的椅子。当他手够不着时&#xff0c;他会站到椅子上再试试。 这次与 NOIp2005 普及组第一题不同的…...