Deep Learning Step7 Computational Graphs in Python
Deep Learning Step7 Computational Graphs in Python The python code below shows forward propagation and back propagation for computational graphs that we learned. # weakref is from asyncio import SendfileNotAvailableError import weakref import numpy as np import contextlib class Config: enable_backprop = True @contextlib.contextmanager def using_config(name, value): old_value = getattr(Config, name) setattr(Config, name, value) try: yield finally: setattr(Config, name, old_value) def no_grad(): return using_config('enable_backprop', False) class Variable: __array_priority__ = 200 def __init__(self, data, name=None): if data is not None: if not isinstance(data, np.ndarray): raise TypeError('{} is not supported'.format(type(data))) # input data of np.ndarray self.data = data self.name = name # grad data of np.ndarray self.grad = N...