当前位置:网站首页>img.shape[-2:]/len(img.shape[-2:]):GeneralizedRCNN:original_image_sizes中的 torch._assert
img.shape[-2:]/len(img.shape[-2:]):GeneralizedRCNN:original_image_sizes中的 torch._assert
2022-07-22 02:48:00 【Eden_mm】
——————————————————————————————————————
知识点补充:
img.shape[-2:]
.shape[0]求0维的样本数量,不准确理解即行数;.shape[1]求1维的样本数量,不准确理解即列数;
.shape[-2:]即倒数第二维度至最后一维度,即最后两维度(-2维度,-1维度),img.shape[-2:]即求出来最后两维度的样本数量,在image的tensor形式中,图片以(C,H,W)存储,故后两维度应该为(H,W),即img.shape[-2:]得到(H,W)
len(img.shape[-2:])
len对shape来说是得到维度的数目,即一维得1,二维得2,len(img.shape)得3,len(img.shape[-2:])即得2.
——————————————————————————————————————
original_image_sizes: List[Tuple[int, int]] = []
for img in images:
val = img.shape[-2:]
torch._assert(
len(val) == 2,
f"expecting the last two dimensions of the Tensor to be H and W instead got {
img.shape[-2:]}",
)
original_image_sizes.append((val[0], val[1]))
中的
torch._assert(
len(val) == 2,
f"expecting the last two dimensions of the Tensor to be H and W instead got {
img.shape[-2:]}",
)
在判断image是不是tensor类型中,val = img.shape[-2:],得到最后两维的数量,即H和W,而len(val),即len(img.shape[-2:])求的是一共有多少维度,即最后两维度,得2,这个断言是怎么起作用的?貌似没特别大的作用。
答:确实没太大作用。做再次判断的作用。在img为一维的时候,val = img.shape[-2:]其实也并不会报错,但是len(img.shape[-2:])就变成了1,报错。
边栏推荐
- Add, delete, check and modify MySQL (second sentence)
- 小乌龟上传远程仓库
- MySQL(28)——事务相关
- RuntimeWarning: Glyph 25152 missing from current font. font. set_ text(s, 0.0, flags=flags)
- nacos基础概念和单机启动
- 欢乐的彝族火把节Joyous Torch Festival of the Yi Nationality
- A Recommendation for interface-based programming
- ROS学习(28)Web GUI
- 上传图片到本机iis服务器,结果以网页地址形式返回,可直接访问
- 商业智能BI分析思维:生产制造行业的现金周期(二)
猜你喜欢
Succès de la construction du cluster expérimental tdengine
欢乐的彝族火把节Joyous Torch Festival of the Yi Nationality
Bi analytical thinking of business intelligence: cash cycle of manufacturing industry (II)
60 open-ended test questions, recite them and get a pay rise directly
Add, delete, check and modify MySQL (second sentence)
Debugging VBS Visual Studio
TDengine学习笔记
Machine learning notes - overview of machine learning system design process
AutoComplete(自动完成)
Zero basic learning canoe panel (2) -- control layout
随机推荐
Part 16: ADC, CAD and DMA direct memory access in stm32
数据库的相关知识
重载(overload)和重写(override)的区别
df. Describe() detailed + usage + Example
The difference between overload and override
深度学习之 8 深度模型优化与正则化
ADB common commands
产品Banner样式类型分析
A Recommendation for interface-based programming
优炫数据库上可以搭建Oracle RAC吗?
[Huawei machine test questions] maximum number of components [2022 Q3 | 100 points]
LeetCode 0128.最长连续序列
【FiddlerTX插件】使用Fiddler抓包腾讯课堂视频下载
如何用一手数据可视化获得老板的青睐,抓住数据可视化关键点
60 open-ended test questions, recite them and get a pay rise directly
Halcon displays point clouds in TXT file format
How to use first-hand data visualization to win the favor of the boss and grasp the key points of data visualization
Tensorboard安装与使用
“码”上赢门票——TDengine开发者大会购票福利第二弹
Barcode (bar code)