当前位置:网站首页>def fasterrcnn_ resnet50_ FPN () instance test
def fasterrcnn_ resnet50_ FPN () instance test
2022-07-29 04:42:00 【Eden_ mm】
Training phase
import torch
import torchvision
from torchvision.models.detection import FasterRCNN_ResNet50_FPN_Weights
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights=FasterRCNN_ResNet50_FPN_Weights.DEFAULT)
# for train
images, boxes = torch.rand(4, 3, 600, 1200), torch.rand(4, 11, 4)
boxes[:, :, 2:4] = boxes[:, :, 0:2] + boxes[:, :, 2:4]
labels = torch.randint(1, 91, (4, 11))
images = list(image for image in images)
targets = []
for i in range(len(images)): # i = 0, 1, 2, 3
d = {
}
d['boxes'] = boxes[i]
d['labels'] = labels[i]
targets.append(d)
output = model(images, targets)
print(output)
#
# # for inference
# model.eval()
#
# x = [torch.rand(3, 300, 400), torch.rand(3, 300, 400)]
# predictions = model(x)
result :
{
'loss_classifier': tensor(0.3633, grad_fn=<NllLossBackward0>), 'loss_box_reg': tensor(0.0262, grad_fn=<DivBackward0>), 'loss_objectness': tensor(1.9085, grad_fn=<BinaryCrossEntropyWithLogitsBackward0>), 'loss_rpn_box_reg': tensor(1.0729, grad_fn=<DivBackward0>)}
The reasoning stage
import torch
import torchvision
from torchvision.models.detection import FasterRCNN_ResNet50_FPN_Weights
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights=FasterRCNN_ResNet50_FPN_Weights.DEFAULT)
# # for train
# images, boxes = torch.rand(4, 3, 600, 1200), torch.rand(4, 11, 4)
# boxes[:, :, 2:4] = boxes[:, :, 0:2] + boxes[:, :, 2:4]
# labels = torch.randint(1, 91, (4, 11))
#
# images = list(image for image in images)
# targets = []
# for i in range(len(images)): # i = 0, 1, 2, 3
# d = {}
# d['boxes'] = boxes[i]
# d['labels'] = labels[i]
# targets.append(d)
#
# output = model(images, targets)
# print(output)
#
# for inference
model.eval()
x = [torch.rand(3, 300, 400), torch.rand(3, 300, 400)]
predictions = model(x)
print(predictions)
result :
It is speculated that the reason why there is no prediction box is that the data is randomly generated
[{
'boxes': tensor([], size=(0, 4), grad_fn=<StackBackward0>), 'labels': tensor([], dtype=torch.int64), 'scores': tensor([], grad_fn=<IndexBackward0>)},
{
'boxes': tensor([], size=(0, 4), grad_fn=<StackBackward0>), 'labels': tensor([], dtype=torch.int64), 'scores': tensor([], grad_fn=<IndexBackward0>)}]
边栏推荐
- Exception resolution: error of not finding edu.stanford.nlp.semgraph.semgrex.semgrexpattern in cococaption package
- 使用近场探头和电流探头进行EMI干扰排查
- Deep analysis of data storage in memory (Advanced C language)
- Unity基础(3)—— unity中的各种坐标系
- Common rules of makefile (make) (II)
- Flutter 手势监听和画板实现
- 恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会
- WebRTC实现简单音视频通话功能
- Actual combat of flutter - DIO of request encapsulation (II)
- DASCTF2022.07赋能赛
猜你喜欢

spinning up安装完使用教程测试是否成功,出现Library“GLU“ not found和‘from pyglet.gl import *错误解决办法

img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)

GCC Basics

Deep analysis of data storage in memory (Advanced C language)

恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会

VScode 一键编译和调试

Recommendation system of online education

Classes and objects (II)

mujoco和mujoco_py安装以及解决libXcursor.so.1:NO such dictionary

Vscode one click compilation and debugging
随机推荐
Idea small settings
正确的用户拖拽方式
使用更灵活、更方便的罗氏线圈
pulsar起client客户端时(client,producer,consumer)各个配置
Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan
[C] PTA 6-8 finding the height of binary tree
Pyqt5 learning pit encounter and pit drainage (2) buttons in qformlayout layout cannot be displayed
Pyqt5 learning pit encounter and pit drainage (3) background picture coverage button style and check button status
Flutter实战-请求封装(二)之dio
Corresponding order of 18 and 25coco data of openpose and joint points
How to build a mobile studio network?
Flutter 手势监听和画板实现
MySQL - deep parsing of MySQL index data structure
Exception resolution: error of not finding edu.stanford.nlp.semgraph.semgrex.semgrexpattern in cococaption package
带你一文理解JS数组
leetcode 686.重复叠加字符串 KMP方法(C语言实现)
数据湖:分布式开源处理引擎Spark
Mysql:The user specified as a definer (‘root‘@‘%‘) does not exist 的解决办法
UE 在场景或UMG中播放视频
网络之以太网