vgg_16_cifar.py 1.8 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle.trainer_config_helpers import *

is_predict = get_config_arg("is_predict", bool, False)

####################Data Configuration ##################
if not is_predict:
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    data_dir = 'data/cifar-out/batches/'
    meta_path = data_dir + 'batches.meta'

    args = {
        'meta': meta_path,
        'mean_img_size': 32,
        'img_size': 32,
        'num_classes': 10,
        'use_jpeg': 1,
        'color': "color"
    }

    define_py_data_sources2(
        train_list="train.list",
        test_list="train.list",
        module='image_provider',
        obj='processData',
        args=args)
Z
zhangjinchao01 已提交
39 40 41

######################Algorithm Configuration #############
settings(
42 43 44 45
    batch_size=128,
    learning_rate=0.1 / 128.0,
    learning_method=MomentumOptimizer(0.9),
    regularization=L2Regularization(0.0005 * 128))
Z
zhangjinchao01 已提交
46 47

#######################Network Configuration #############
48 49 50
data_size = 3 * 32 * 32
label_size = 10
img = data_layer(name='image', size=data_size)
51
# small_vgg is predefined in trainer_config_helpers.networks
52
predict = small_vgg(input_image=img, num_channels=3, num_classes=label_size)
Z
zhangjinchao01 已提交
53 54 55 56 57 58

if not is_predict:
    lbl = data_layer(name="label", size=label_size)
    outputs(classification_cost(input=predict, label=lbl))
else:
    outputs(predict)