Python* API Reference for Intel® Data Analytics Acceleration Library 2019 Update 5

split_layer_dense_batch.py

1 # file: split_layer_dense_batch.py
2 #===============================================================================
3 # Copyright 2014-2019 Intel Corporation.
4 #
5 # This software and the related documents are Intel copyrighted materials, and
6 # your use of them is governed by the express license under which they were
7 # provided to you (License). Unless the License provides otherwise, you may not
8 # use, modify, copy, publish, distribute, disclose or transmit this software or
9 # the related documents without Intel's prior written permission.
10 #
11 # This software and the related documents are provided as is, with no express
12 # or implied warranties, other than those that are expressly stated in the
13 # License.
14 #===============================================================================
15 
16 #
17 # ! Content:
18 # ! Python example of forward and backward split layer usage
19 # !
20 # !*****************************************************************************
21 
22 #
23 
24 
25 #
26 
27 import os
28 import sys
29 
30 from daal.algorithms.neural_networks import layers
31 from daal.algorithms.neural_networks.layers import split
32 
33 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
34 if utils_folder not in sys.path:
35  sys.path.insert(0, utils_folder)
36 from utils import printTensor, readTensorFromCSV
37 
38 # Input data set parameters
39 datasetName = os.path.join("..", "data", "batch", "layer.csv")
40 nOutputs = 3
41 nInputs = 3
42 
43 if __name__ == "__main__":
44 
45  # Read datasetFileName from a file and create a tensor to store input data
46  tensorData = readTensorFromCSV(datasetName)
47 
48  # Create an algorithm to compute forward split layer results using default method
49  splitLayerForward = split.forward.Batch()
50 
51  # Set parameters for the forward split layer
52  splitLayerForward.parameter.nOutputs = nOutputs
53  splitLayerForward.parameter.nInputs = nInputs
54 
55  # Set input objects for the forward split layer
56  splitLayerForward.input.setInput(layers.forward.data, tensorData)
57 
58  printTensor(tensorData, "Split layer input (first 5 rows):", 5)
59 
60  # Compute forward split layer results
61  forwardResult = splitLayerForward.compute()
62 
63  # Print the results of the forward split layer
64  for i in range(nOutputs):
65  printTensor(forwardResult.getResultLayerData(split.forward.valueCollection, i),
66  "Forward split layer result (first 5 rows):", 5)
67 
68  # Create an algorithm to compute backward split layer results using default method
69  splitLayerBackward = split.backward.Batch()
70 
71  # Set parameters for the backward split layer
72  splitLayerBackward.parameter.nOutputs = nOutputs
73  splitLayerBackward.parameter.nInputs = nInputs
74 
75  # Set input objects for the backward split layer
76  splitLayerBackward.input.setInputLayerData(split.backward.inputGradientCollection,
77  forwardResult.getResultLayerData(split.forward.valueCollection))
78 
79  # Compute backward split layer results
80  backwardResult = splitLayerBackward.compute()
81 
82  # Print the results of the backward split layer
83  printTensor(backwardResult.getResult(layers.backward.gradient), "Backward split layer result (first 5 rows):", 5)

For more complete information about compiler optimizations, see our Optimization Notice.