当前位置:网站首页>Common programming records - parser = argparse ArgumentParser()
Common programming records - parser = argparse ArgumentParser()
2022-04-23 06:00:00 【umbrellalalalala】
In many pytorch Written in the AI project , Can see such a sentence :parser = argparse.ArgumentParser(), This article simply records their usage
Partial content reference :
https://blog.csdn.net/lizhiyuanbest/article/details/104975848
Catalog
The way 1— Single parameter
establish a.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number", type=int)
args = parser.parse_args()
s = args.square ** 2
print(s)
Command line execution :
$ python a.py 2
4
The way 2— Multiple parameters
establish b.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number", type=int)
parser.add_argument("add1", help="display a sum of two given numbers", type=int)
parser.add_argument("add2", help="display a sum of two given numbers", type=int)
args = parser.parse_args()
s = args.square ** 2
a = args.add1 + args.add2
print(s)
print(a)
Command line execution results :
$ python b.py 2 10 20
4
30
It can be seen that three integers are assigned to three parameters in order
The way 3— Out of order assignment
establish c.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--square", help="display a square of a given number", type=int)
parser.add_argument("--add1", help="display a sum of two given numbers", type=int)
parser.add_argument("--add2", help="display a sum of two given numbers", type=int)
args = parser.parse_args()
s = args.square ** 2
a = args.add1 + args.add2
print(s)
print(a)
️ Note that the parameter is preceded by --
Command line operation mode 1:
$ python c.py --square 2 --add1 10 --add2 20
4
30
Command line operation mode 2( Out of order ):
$ python c.py --add1 2 --add2 10 --square 20
400
12
knock pytorch It should be enough for students to master these
版权声明
本文为[umbrellalalalala]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230543450923.html
边栏推荐
- You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
- Multithreading and high concurrency (1) -- basic knowledge of threads (implementation, common methods, state)
- protected( 被 protected 修饰的成员对于本包和其子类可见)
- 对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
- Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
- Pytorch学习记录(三):神经网络的结构+使用Sequential、Module定义模型
- Pytorch学习记录(七):处理数据和训练模型的技巧
- Pytorch——数据加载和处理
- ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
- Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
猜你喜欢

Configure domestic image accelerator for yarn

Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.

PyQy5学习(三):QLineEdit+QTextEdit

PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码

Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)

CONDA virtual environment management (create, delete, clone, rename, export and import)

Pytorch学习记录(三):神经网络的结构+使用Sequential、Module定义模型

Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解

Practical operation - Nacos installation and configuration

Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
随机推荐
PyTorch入门小笔记——利用简单例子观察前向传播各个层输出的size
Fundamentals of digital image processing (Gonzalez) I
Solution record of slow access speed of SMB service in redhat6
创建企业邮箱账户命令
线性代数第一章-行列式
PreparedStatement防止SQL注入
MySQL realizes master-slave replication / master-slave synchronization
sklearn之 Gaussian Processes
String notes
图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
建表到页面完整实例演示—联表查询
Automatic control (Han min version)
K/3 WISE系统考勤客户端日期只能选到2019年问题
线性代数第三章-矩阵的初等变换与线性方程组
SQL基础:初识数据库与SQL-安装与基本介绍等—阿里云天池
在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package
Pytorch学习记录(九):Pytorch中卷积神经网络
lambda表达式
JDBC工具类封装