python默认参数陷阱_技巧18-默认参数的陷阱.ipynb

{

"cells": [

{

"cell_type": "code",

"execution_count": 1,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'a', 'a']"

]

},

"execution_count": 1,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"def bad_default_arg(s, times, target=[]):\n",

" for _ in range(times):\n",

" target.append(s)\n",

" return target\n",

"\n",

"bad_default_arg(s='a', times=3)"

]

},

{

"cell_type": "code",

"execution_count": 2,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'b', 'b', 'b']"

]

},

"execution_count": 2,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"bad_default_arg(s='b', times=3, target=['a'])"

]

},

{

"cell_type": "code",

"execution_count": 3,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'a', 'a', 'AB', 'AB']"

]

},

"execution_count": 3,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"bad_default_arg(s='AB', times=2)"

]

},

{

"cell_type": "code",

"execution_count": 4,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'a', 'a', 'AB', 'AB', 'CD', 'CD']"

]

},

"execution_count": 4,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"bad_default_arg(s='CD', times=2)"

]

},

{

"cell_type": "code",

"execution_count": 5,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['c', 'AB', 'AB']"

]

},

"execution_count": 5,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"bad_default_arg(s='AB', times=2, target=['c'])"

]

},

{

"cell_type": "code",

"execution_count": 6,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'a', 'a', 'AB', 'AB', 'CD', 'CD', 'EF', 'EF']"

]

},

"execution_count": 6,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"bad_default_arg(s='EF', times=2)"

]

},

{

"cell_type": "code",

"execution_count": 8,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'a', 'a']"

]

},

"execution_count": 8,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"def good_default_arg(s, times, target=None):\n",

" if target is None:\n",

" target = []\n",

" for _ in range(times):\n",

" target.append(s)\n",

" return target\n",

"\n",

"good_default_arg(s='a', times=3)"

]

},

{

"cell_type": "code",

"execution_count": 9,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['a', 'a', 'a']"

]

},

"execution_count": 9,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"good_default_arg(s='a', times=3)"

]

},

{

"cell_type": "code",

"execution_count": 10,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['B', 'B', 'B']"

]

},

"execution_count": 10,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"good_default_arg(s='B', times=3)"

]

},

{

"cell_type": "code",

"execution_count": 11,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

"['FF', 'a', 'a', 'a']"

]

},

"execution_count": 11,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"good_default_arg(s='a', times=3, target=['FF'])"

]

},

{

"cell_type": "code",

"execution_count": null,

"metadata": {},

"outputs": [],

"source": []

}

],

"metadata": {

"kernelspec": {

"display_name": "Python 3",

"language": "python",

"name": "python3"

},

"language_info": {

"codemirror_mode": {

"name": "ipython",

"version": 3

},

"file_extension": ".py",

"mimetype": "text/x-python",

"name": "python",

"nbconvert_exporter": "python",

"pygments_lexer": "ipython3",

"version": "3.7.0"

}

},

"nbformat": 4,

"nbformat_minor": 2

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这是一条使用 Python 脚本进行目标检测评估的命令。该命令使用了一个名为 eval_rcnn.py 的 Python 脚本,并传入了三个参数: 1. --cfg_file:表示使用的配置文件,默认为 cfgs/default.yaml; 2. --eval_mode:表示评估模式,此处为 rcnn,表示使用 RCNN 模型进行评估; 3. --eval_all:表示评估全部数据集,即对所有图像进行评估。 这个命令的具体作用是评估 RCNN 模型在指定数据集上的目标检测性能,并输出评估结果。 ### 回答2: 这条命令是用于在Python中执行一个名为eval_rcnn.py的脚本。它使用了三个指定参数: 1. --cfg_file:指定要使用的配置文件,默认为cfgs/default.yaml。配置文件通常包含了一些模型的设置,如网络结构、训练参数、数据集路径等。 2. --eval_mode:指定评估模式为rcnn,其中"rcnn"通常表示使用R-CNN(Region Proposal Network-Convolutional Neural Network)算法进行目标检测。 3. --eval_all:表示对所有样本进行评估,而不仅仅是某个子集。这是一种在测试阶段进行全面评估的常见做法,以评估模型在整个数据集上的性能。 综上所述,该条命令的目的是在Python环境中运行一个名为eval_rcnn.py的脚本,使用指定的配置文件(cfgs/default.yaml)对R-CNN算法进行目标检测,并对整个数据集进行评估。 ### 回答3: 这个命令是用于在 Python 中运行 eval_rcnn.py 脚本,它的参数含义如下: --cfg_file cfgs/default.yaml:指定配置文件为 cfgs/default.yaml。配置文件是用来设置模型的超参数和其他相关参数的文件,这里使用的是 default.yaml 文件。 --eval_mode rcnn:设置评估模式为 rcnn。这表示模型会根据预训练的 RCNN 算法进行评估。 --eval_all:这个参数用来进行全面评估。它会评估模型在数据集中的所有样本上的性能,而不仅仅是某个特定的子集。通常在训练完成后,使用该参数来对模型进行全面评估,以得到一个更全面的性能指标。 总之,这个命令会使用指定的模型配置文件和评估模式,在所有的数据样本上对模型进行评估,并输出评估结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值