#edit-mode: -*- python -*- # 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 * TrainData(SimpleData( files = "trainer/tests/sample_filelist.txt", feat_dim = 3, context_len = 0, buffer_capacity = 1000000)) TestData(SimpleData( files = "trainer/tests/sample_filelist.txt", feat_dim = 3, context_len = 0, buffer_capacity = 1000000)) settings(batch_size = 100) # Output layer, label layer, cost layer, preferably set to the same environment. output_device = 0 # Input Layer does not need to specify the device number. data = data_layer(name='input', size=3) # Calculate in the CPU. fc1 = fc_layer(input=data, size=5, bias_attr=True, layer_attr=ExtraAttr(device=-1), act=SigmoidActivation()) # Calculate in the GPU 0. fc2 = fc_layer(input=fc1, size=10, bias_attr=True, layer_attr=ExtraAttr(device=0), act=SigmoidActivation()) # Calculate in the GPU 1. fc3 = fc_layer(input=fc1, size=10, bias_attr=True, layer_attr=ExtraAttr(device=1), act=SigmoidActivation()) # Calculate in the GPU 0. fc4 = fc_layer(input=[fc2,fc3], size=10, bias_attr=True, layer_attr=ExtraAttr(device=0), act=SigmoidActivation()) # Calculate in the GPU 1. fc5 = fc_layer(input=[fc2,fc3], size=10, bias_attr=True, layer_attr=ExtraAttr(device=1), act=SigmoidActivation()) output = fc_layer(input=[fc4,fc5], size=10, bias_attr=True, layer_attr=ExtraAttr(device=output_device), act=SoftmaxActivation()) if get_config_arg('with_cost', bool, True): # This is for training the neural network. # We need to have another data layer for label # and a layer for calculating cost lbl = data_layer(name='label', size=1, layer_attr=ExtraAttr(device=output_device)) outputs(classification_cost(input=output, label=lbl, layer_attr=ExtraAttr(device=output_device))) else: # This is for prediction where we don't have label # and don't need to calculate cost outputs(output)