【发布时间】:2021-12-06 10:13:25
【问题描述】:
我是 PyTorch 用户,但最近阅读了一些使用 tensorflow 实现的代码。 我的问题是,如果我们只有这样一个简单的神经网络,input 的大小在哪里指定?或者这个模型是否允许使用 variable 大小的输入?
class SimpleNet(tf.keras.Model):
def __init__(self):
super(SimpleNet, self).__init__()
activation = tf.keras.activations.tanh
self.features = [
#Where is the input size specified?
tf.keras.layers.Dense(89, activation),
tf.keras.layers.Dense(6 * 32, activation),
tf.keras.layers.Dense(32, activation),
tf.keras.layers.Dense(1),
]
def process(self, x):
x = apply_layers(x, self.features)
return x
...
【问题讨论】:
-
这里的大小不能变。如果未指定输入大小,例如使用第一层 Input(),模型会在第一次调用时根据数据的形状 (tensorflow.org/guide/keras/sequential_model) 初始化其权重。
标签: python tensorflow deep-learning