PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.24k stars 5.58k forks source link

Parameters intialization #11591

Closed JiahaoYao closed 6 years ago

JiahaoYao commented 6 years ago
# build the one layer conv
import paddle.v2 as paddle

def Oneconv(input, class_dim):
    ch_in=3
    ch_out=64
    filter_size=7
    stride=2
    padding=3
    out = paddle.layer.img_conv(
        input=input,
        filter_size=filter_size,
        num_channels=ch_in,
        num_filters=ch_out,
        stride=stride,
        padding=padding,
        act=paddle.activation.Linear(),
        param_attr = paddle.attr.Param(name='___conv_0__.w0', initial_mean=0.0, initial_std=0.0, initial_max=3, initial_min = -3),
        bias_attr=False)
    return out

import paddle.v2 as paddle
import paddle.trainer_config_helpers.layers as layers
import numpy as np

# PaddlePaddle init
paddle.init(use_gpu=False, trainer_count=1)

# Use 3 * 331 * 331 or 3 * 299 * 299 for DATA_DIM in Inception-ResNet-v2.
DATA_DIM = 3 * 224 * 224
CLASS_DIM = 1001
BATCH_SIZE = 1

image = paddle.layer.data(
    name="image", type=paddle.data_type.dense_vector(DATA_DIM))
lbl = paddle.layer.data(
    name="label", type=paddle.data_type.integer_value(CLASS_DIM))

out = Oneconv(image, class_dim=CLASS_DIM)

parameters = paddle.parameters.create(out)

print(parameters.get('___conv_0__.w0')[0][:100])
w = parameters.get('___conv_0__.w0')
print(w.shape)

I build a one layer convolution layer. It tries to set the parameter to be the Gaussian mean=0, std=0. When I try to print this parameter out, it is either too big or too small. It seems that the variance is so big.

image

Does this mean that the parameter initialization is wrong?

JiayiFeng commented 6 years ago

That is because parameters are never initialized in your configuration. Please add a loss to your network and configure a trainer. https://github.com/PaddlePaddle/Paddle/blob/59bfa4911d36820ba64f3f6057a88246ede0fa11/doc/v2/getstarted/concepts/src/train.py#L32-L35 Parameters are supposed to be initialized during the creating of a trainer.

JiahaoYao commented 6 years ago

Thank you. I used to suppose that it had already initialized the parameters.