Tool/Keras(2)
-
3. Making new Layers and Models via subclassing
import tensorflow as tf import numpy as np from tensorflow import keras The Layer class: the combination of state (weights) and some computation A layer encapsulates both a state (the layer's "weights") and a transformation from inputs to outputs (a "call", the layer's forward pass). class CustomLinear1(keras.layers.Layer): def __init__(self, d_in, d_out): super().__init__() w_init = tf.random_n..
2022.03.12 -
2. The Functional API
The main idea is that a deep learning model is usually a directed acyclic graph(DAG) of layers. So the functional API is a way to build graphs of layers. import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers Create model by funtional API To build this model using the functional API: Creating an input node(keras.input) which return information about the shape an..
2022.03.12