cmd批处理命令~%dp0与~%dpn1的解析

1、最简单的做法是在cmd命令输入:for /?,回车,就能看到详细的解析

对一组文件中的每一个文件执行某个特定命令。

FOR %variable IN (set) DO command [command-parameters]

%variable 指定一个单一字母可替换的参数。 (set) 指定一个或一组文件。可以使用通配符。 command
指定对每个文件执行的命令。 command-parameters
为特定命令指定参数或命令行开关。

在批处理程序中使用 FOR 命令时,指定变量请使用 %%variable 而不要用 %variable。变量名称是区分大小写的,所以 %i
不同于 %I.

如果启用命令扩展,则会支持下列 FOR 命令的其他格式:

FOR /D %variable IN (set) DO command [command-parameters]

如果集中包含通配符,则指定与目录名匹配,而不与文件名匹配。

FOR /R [[drive:]path] %variable IN (set) DO command
[command-parameters]

检查以 [drive:]path 为根的目录树,指向每个目录中的 FOR 语句。
如果在 /R 后没有指定目录规范,则使用当前目录。如果集仅为一个单点(.)字符,
则枚举该目录树。

FOR /L %variable IN (start,step,end) DO command [command-parameters]

该集表示以增量形式从开始到结束的一个数字序列。因此,(1,1,5)将产生序列
1 2 3 4 5,(5,-1,1)将产生序列(5 4 3 2 1)

FOR /F [“options”] %variable IN (file-set) DO command
[command-parameters] FOR /F [“options”] %variable IN (“string”) DO
command [command-parameters] FOR /F [“options”] %variable IN
(‘command’) DO command [command-parameters]

或者,如果有 usebackq 选项:

FOR /F [“options”] %variable IN (file-set) DO command
[command-parameters] FOR /F [“options”] %variable IN (“string”) DO
command [command-parameters] FOR /F [“options”] %variable IN
(‘command’) DO command [command-parameters]

fileset 为一个或多个文件名。继续到 fileset 中的下一个文件之前,
每份文件都被打开、读取并经过处理。处理包括读取文件,将其分成一行行的文字,
然后将每行解析成零或更多的符号。然后用已找到的符号字符串变量值调用 For 循环。
以默认方式,/F 通过每个文件的每一行中分开的第一个空白符号。跳过空白行。
您可通过指定可选 "options" 参数替代默认解析操作。这个带引号的字符串包括一个
或多个指定不同解析选项的关键字。这些关键字为:

    eol=c           - 指一个行注释字符的结尾(就一个)

当然,也可以看到国外学者的解释:
在这里插入图片描述
我们写个名字为a.bat的bat脚本看看效果:

@echo off
set BAT_DIR=%~dp0

set DEST_BASE=%~dpn1
set DEST_BASE1=%~p1
set DEST_BASE2=%~n1
set DEST_BASE3=%~s1
set DEST_BASE4=%~nx1
set DEST_BASE5=%~f1
set DEST_BASE6=%~dp1

echo ~p1 = %DEST_BASE1%
echo ~s1 = %DEST_BASE3%
echo ~n1 = %DEST_BASE2%
echo ~nx1 = %DEST_BASE4%
echo ~dp1 = %DEST_BASE6%
echo ~dpn1 = %DEST_BASE%
echo ~f1 = %DEST_BASE5%

输入为:a.bat C:\Users\Administrator.USER-20190314HO\Desktop\vivo-obfuscated-1.6.15.jar
输出结果为:

在这里插入图片描述

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
首先,我们需要安装PyTorch和其他必要的库。可以使用以下命令安装PyTorch: ``` pip install torch torchvision ``` 其他库可以使用以下命令安装: ``` pip install numpy pandas matplotlib opencv-python ``` 接下来,我们需要下载DPN92预训练模型的权重。可以使用以下命令下载: ``` wget https://github.com/c0nn3r/DPN/releases/download/v2.0/DPN92_extra_5k.pth.tar ``` 现在开始设计模型。我们将使用PyTorch中的预训练模型和自定义头来实现图像检测和分类。以下是完整的代码: ```python import torch import torch.nn as nn import torch.nn.functional as F import torchvision.transforms as transforms import cv2 import numpy as np # Define the custom head for object detection class DetectionHead(nn.Module): def __init__(self, in_channels, num_classes): super(DetectionHead, self).__init__() self.conv1 = nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1) self.bn1 = nn.BatchNorm2d(in_channels) self.conv2 = nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1) self.bn2 = nn.BatchNorm2d(in_channels) self.conv3 = nn.Conv2d(in_channels, in_channels, kernel_size=3, stride=1, padding=1) self.bn3 = nn.BatchNorm2d(in_channels) self.conv4 = nn.Conv2d(in_channels, num_classes * 5, kernel_size=3, stride=1, padding=1) def forward(self, x): x = F.relu(self.bn1(self.conv1(x))) x = F.relu(self.bn2(self.conv2(x))) x = F.relu(self.bn3(self.conv3(x))) x = self.conv4(x) return x # Define the model class DPN92Detection(nn.Module): def __init__(self, num_classes): super(DPN92Detection, self).__init__() self.dpn92 = torch.hub.load('rwightman/pytorch-dpn-pretrained', 'dpn92', pretrained=True) self.head = DetectionHead(2688, num_classes) def forward(self, x): x = self.dpn92.features(x) x = F.avg_pool2d(x, kernel_size=7, stride=1) x = x.view(x.size(0), -1) x = self.head(x) return x # Define the class names class_names = ['class0', 'class1', 'class2', 'class3', 'class4'] # Load the model and the weights model = DPN92Detection(num_classes=len(class_names)) model.load_state_dict(torch.load('DPN92_extra_5k.pth.tar', map_location='cpu')['state_dict']) # Set the model to evaluation mode model.eval() # Define the image transformer image_transforms = transforms.Compose([ transforms.ToPILImage(), transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]), ]) # Load the image image = cv2.imread('test.jpg') # Transform the image input_image = image_transforms(image) input_image = input_image.unsqueeze(0) # Make a prediction with torch.no_grad(): output = model(input_image) # Get the class probabilities class_probs = F.softmax(output[:, :len(class_names)], dim=1) # Get the bounding box coordinates, sizes and class indices coords_sizes_classes = output[:, len(class_names):].view(-1, 5) coords_sizes_classes[:, :2] = torch.sigmoid(coords_sizes_classes[:, :2]) coords_sizes_classes[:, 2] = torch.exp(coords_sizes_classes[:, 2]) coords_sizes_classes[:, 3:5] = torch.argmax(coords_sizes_classes[:, 3:], dim=1).unsqueeze(1) coords_sizes_classes = coords_sizes_classes.cpu().numpy() # Filter out the boxes with low confidence conf_threshold = 0.5 filtered_boxes = coords_sizes_classes[class_probs[0] > conf_threshold] # Draw the boxes on the image for box in filtered_boxes: x, y, w, h, c = box x *= image.shape[1] y *= image.shape[0] w *= image.shape[1] h *= image.shape[0] x1 = int(x - w / 2) y1 = int(y - h / 2) x2 = int(x + w / 2) y2 = int(y + h / 2) cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2) cv2.putText(image, class_names[int(c)], (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) # Show the image cv2.imshow('Image', image) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在上面的代码中,我们定义了一个名为`DetectionHead`的自定义头,用于检测图像中的对象,并输出它们的坐标、大小和类别。然后,我们定义了一个名为`DPN92Detection`的模型,该模型使用DPN92预训练模型和自定义头进行图像检测和分类。我们还定义了一些变量,如类名、图像变换器、置信度阈值等。最后,我们将模型和权重加载到内存中,并使用`cv2`库加载图像。我们将图像传递给模型,然后使用`softmax`函数获取类别概率,使用`sigmoid`和`exp`函数获取边界框的坐标和大小,并使用`argmax`函数获取类别索引。最后,我们过滤掉低置信度的边界框,并将它们绘制在原始图像上。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值