expected in_dims[1] == filter_dims[1] * groups, but received in_dims[1]:512 != filter_dims[1] * groups:1024
Created by: stevehejianguo
为使您的问题得到快速解决,在建立Issue前,请您先通过如下方式搜索是否有相似问题:【搜索issue关键字】【使用labels筛选】【官方文档】
建立issue时,为快速解决问题,请您根据使用情况给出如下信息:
- 标题:简洁、精准描述您的问题,例如“ssd 模型前置lstm报错 ”
- 版本、环境信息: 1)PaddlePaddle版本:请提供PaddlePaddle版本号,例如1.1或CommitID 2)CPU:请提供CPU型号,MKL/OpenBlas/MKLDNN/等数学库的使用情况 3)GPU:请提供GPU型号,CUDA和CUDNN版本号 4)系统环境:请说明系统类型、版本(例如Mac OS 10.14),Python版本
- 模型信息 1)模型名称 2)使用数据集名称 3)使用算法名称 4)模型链接
- 复现信息:如为报错,请给出复现环境、复现步骤
- 问题描述:请详细描述您的问题,同步贴出报错信息、日志/代码关键片段
Thank you for contributing to PaddlePaddle. Before submitting the issue, you could search issue in the github.Probably there was a similar issue submitted or resolved before. If there is no solution,please make sure that this is a issue of models including the following details: System information -PaddlePaddle version (eg.1.1)or CommitID -CPU: including CPUMKL/OpenBlas/MKLDNN version -GPU: including CUDA/CUDNN version -OS Platform (eg.Mac OS 10.14) -Python version -Name of Models&Dataset/details of operator To Reproduce Steps to reproduce the behavior Describe your current behavior Code to reproduce the issue Other info / logs
环境是aistudio,gpu版 数据集是coco2017 模型如下:
_C = AttrDict() cfg = _C
Training options
_C.debug = True
Snapshot period
_C.snapshot_iter = 2000
min valid area for gt boxes
_C.gt_min_area = -1
max target box number in an image
_C.max_box_num = 24
Training options
valid score threshold to include boxes
_C.valid_thresh = 0.005
threshold vale for box non-max suppression
_C.nms_thresh = 0.45
the number of top k boxes to perform nms
_C.nms_topk = 400
the number of output boxes after nms
_C.nms_posk = 100
score threshold for draw box in debug mode
_C.draw_thresh = 0.5
Model options
pixel mean values
_C.pixel_means = [0.485, 0.456, 0.406]
pixel std values
_C.pixel_stds = [0.229, 0.224, 0.225]
anchors box weight and height
_C.anchors = [ 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 ]
anchor mask of each yolo layer
_C.anchor_masks = [[3, 4, 5], [0, 1, 2]]
IoU threshold to ignore objectness loss of pred box
_C.ignore_thresh = .7
SOLVER options
batch size
_C.batch_size = 8
derived learning rate the to get the final learning rate.
_C.learning_rate = 0.001
maximum number of iterations
_C.max_iter = 500200
warm up to learning rate
_C.warm_up_iter = 4000 _C.warm_up_factor = 0.
lr steps_with_decay
_C.lr_steps = [400000, 450000] _C.lr_gamma = 0.1
L2 regularization hyperparameter
_C.weight_decay = 0.0005
momentum with SGD
_C.momentum = 0.9
ENV options
support both CPU and GPU
_C.use_gpu = True
Class number
_C.class_num = 80
dataset path
_C.train_file_list = 'annotations/instances_train2017.json' _C.train_data_dir = 'train2017' _C.val_file_list = 'annotations/instances_val2017.json' _C.val_data_dir = 'val2017'
def add_Tiny_conv_body(body_input, is_test=True): convs = [32, 64, 128, 256] blocks = [] conv = conv_pool(body_input, 16, 3, 1, 1, act='leaky', is_test=is_test, name='yolo_input.0') for i,item in enumerate(convs): conv = conv_pool(conv, item, 3, 1, 1, act='leaky', is_test=is_test, name='yolo_input.{}'.format(i+1)) if item == 128: blocks.append(conv) conv = conv_bn_layer(conv, 512, 3, 1, 1, act='leaky', is_test=is_test, name='yolo_input.5') conv = conv_bn_layer(conv, 1024, 3, 1, 1, act='leaky', is_test=is_test, name='yolo_input.6') blocks.append(conv) return blocks[::-1]
======================
def upsample(input, scale=2, name=None): # get dynamic upsample output shape shape_nchw = fluid.layers.shape(input) shape_hw = fluid.layers.slice(shape_nchw, axes=[0], starts=[2], ends=[4]) shape_hw.stop_gradient = True in_shape = fluid.layers.cast(shape_hw, dtype='int32') out_shape = in_shape * scale out_shape.stop_gradient = True
# reisze by actual_shape
out = fluid.layers.resize_nearest(
input=input, scale=scale, actual_shape=out_shape, name=name)
return out
class YOLOv3_Tiny(object): def init(self, is_train=True, use_random=True): self.is_train = is_train self.use_random = use_random self.outputs = [] self.losses = [] self.downsample = 32
def build_input(self):
self.image_shape = [3, 416, 416]
if self.is_train:
self.py_reader = fluid.layers.py_reader(
capacity=64,
shapes=[[-1] + self.image_shape, [-1, cfg.max_box_num, 4],
[-1, cfg.max_box_num], [-1, cfg.max_box_num]],
lod_levels=[0, 0, 0, 0],
dtypes=['float32'] * 2 + ['int32'] + ['float32'],
use_double_buffer=True)
self.image, self.gtbox, self.gtlabel, self.gtscore = \
fluid.layers.read_file(self.py_reader)
else:
self.image = fluid.layers.data(
name='image', shape=self.image_shape, dtype='float32')
self.im_shape = fluid.layers.data(
name="im_shape", shape=[2], dtype='int32')
self.im_id = fluid.layers.data(
name="im_id", shape=[1], dtype='int32')
def feeds(self):
if not self.is_train:
return [self.image, self.im_id, self.im_shape]
return [self.image, self.gtbox, self.gtlabel, self.gtscore]
def build_model(self):
self.build_input()
self.outputs = []
self.boxes = []
self.scores = []
blocks = add_Tiny_conv_body(self.image, not self.is_train)
for i, block in enumerate(blocks):
if i > 0:
block = fluid.layers.concat(input=[route, block], axis=1)
tip = conv_bn_layer(block,
256,
3,
1,
1,
act='leaky',
is_test=(not self.is_train),
name='yolo_block.conf.1.weights.0')
else:
route = conv_bn_layer(block,
256,
1,
1,
0,
act='leaky',
is_test=(not self.is_train),
name='yolo_block.conf.0.weights.0')
tip = conv_bn_layer(route,
512,
3,
1,
1,
act='leaky',
is_test=(not self.is_train),
name='yolo_block.conf.0.weights.1')
# out channel number = mask_num * (5 + class_num)
num_filters = len(cfg.anchor_masks[i]) * (cfg.class_num + 5)
block_out = fluid.layers.conv2d(
input=tip,
num_filters=num_filters,
filter_size=1,
stride=1,
padding=0,
act=None,
param_attr=ParamAttr(
initializer=fluid.initializer.Normal(0., 0.02),
name="yolo_output.{}.conv.weights".format(i)),
bias_attr=ParamAttr(
initializer=fluid.initializer.Constant(0.0),
regularizer=L2Decay(0.),
name="yolo_output.{}.conv.bias".format(i)))
self.outputs.append(block_out)
if i < len(blocks) - 1:
route = conv_bn_layer(
input=route,
ch_out=128,
filter_size=1,
stride=1,
padding=0,
is_test=(not self.is_train),
name="yolo_transition.{}".format(i))
# upsample
route = upsample(route)
for i, out in enumerate(self.outputs):
anchor_mask = cfg.anchor_masks[i]
if self.is_train:
loss = fluid.layers.yolov3_loss(
x=out,
gt_box=self.gtbox,
gt_label=self.gtlabel,
gt_score=self.gtscore,
anchors=cfg.anchors,
anchor_mask=anchor_mask,
class_num=cfg.class_num,
ignore_thresh=cfg.ignore_thresh,
downsample_ratio=self.downsample,
use_label_smooth=bool(cfg.label_smooth),
name="yolo_loss" + str(i))
self.losses.append(fluid.layers.reduce_mean(loss))
else:
mask_anchors = []
for m in anchor_mask:
mask_anchors.append(cfg.anchors[2 * m])
mask_anchors.append(cfg.anchors[2 * m + 1])
boxes, scores = fluid.layers.yolo_box(
x=out,
img_size=self.im_shape,
anchors=mask_anchors,
class_num=cfg.class_num,
conf_thresh=cfg.valid_thresh,
downsample_ratio=self.downsample,
name="yolo_box" + str(i))
self.boxes.append(boxes)
self.scores.append(
fluid.layers.transpose(
scores, perm=[0, 2, 1]))
self.downsample //= 2
def loss(self):
return sum(self.losses)
def get_pred(self):
yolo_boxes = fluid.layers.concat(self.boxes, axis=1)
yolo_scores = fluid.layers.concat(self.scores, axis=2)
return fluid.layers.multiclass_nms(
bboxes=yolo_boxes,
scores=yolo_scores,
score_threshold=cfg.valid_thresh,
nms_top_k=cfg.nms_topk,
keep_top_k=cfg.nms_posk,
nms_threshold=cfg.nms_thresh,
background_label=-1,
name="multiclass_nms")
===================== 训练的代码省略了。模型可以build成功,数据加载完,运行就报错了。训练的代码是参考官方model里面的yolov3的代码。