./configure --ninja --node-builtin-modules-path `pwd`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Placeholder(): | |
| def __init__(self): | |
| self.value = None | |
| _default_graph.placeholders.append(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Variable(): | |
| def __init__(self, initial_value=None): | |
| self.value = initial_value | |
| _default_graph.variables.append(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def topology_sort(operation): | |
| ordering = [] | |
| visited_nodes = set() | |
| def recursive_helper(node): | |
| if isinstance(node, Operation): | |
| for input_node in node.input_nodes: | |
| if input_node not in visited_nodes: | |
| recursive_helper(input_node) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Session(): | |
| def run(self, operation, feed_dict={}): | |
| nodes_sorted = topology_sort(operation) | |
| for node in nodes_sorted: | |
| if type(node) == Placeholder: | |
| node.output = feed_dict[node] | |
| elif type(node) == Variable or type(node) == Constant: | |
| node.output = node.value | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tf_api as tf | |
| # create default graph | |
| tf.Graph().as_default() | |
| # construct computational graph by creating some nodes | |
| a = tf.Constant(15) | |
| b = tf.Constant(5) | |
| prod = tf.multiply(a, b) | |
| sum = tf.add(a, b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BinaryOperation(Operation): | |
| def __init__(self, a, b): | |
| super().__init__([a, b]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class multiply(BinaryOperation): | |
| """ | |
| Computes a * b, element-wise | |
| """ | |
| def forward(self, a, b): | |
| return a * b | |
| def backward(self, upstream_grad): | |
| raise NotImplementedError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import tf_api as tf | |
| # Create model | |
| model = lambda x: 1.23 * x + 10 | |
| # Create small dataset of 5 entries | |
| train_X = np.linspace(0, 5, 5).reshape((-1, 1)) | |
| train_Y = np.array([model(x) for x in train_X]).reshape((-1, 1)) |
OlderNewer