[英]Re-write TensorFlow into Keras with tf.keras
I wan to re-write TensorFlow code into Keras. 我想将TensorFlow代码重新写入Keras。 I just wonder if you can use for this purpose the
tf.keras.layers
to just replace the tf.layers
? 我只是想知道您是否可以为此目的使用
tf.keras.layers
来替换tf.layers
?
Like 喜欢
tf.layers.max_pooling2d()
to: 至:
tf.keras.layers.max_pooling2d()
Can I re-write TensorFlow to Keras in this way? 我可以通过这种方式将TensorFlow重写为Keras吗?
Does this define a proper Keras model where you can use the model.fit
method? 这是否定义了合适的
model.fit
模型,您可以在其中使用model.fit
方法?
First of all, I think you meant tf.keras.layers.MaxPool2D
, which is a class, not a function. 首先,我认为您的意思是
tf.keras.layers.MaxPool2D
,它是一个类,而不是一个函数。 If I got your point, it shouldn't be an issue. 如果我明白你的意思,那应该不是问题。 There are some minor difference in syntax, but nothing serious.
语法上有一些细微的差别,但没什么严重的。 Besides,
tf.keras.layers
is a direct substitute for tf.layers
. 此外,
tf.keras.layers
是tf.keras.layers
的直接替代tf.layers
。 As per official docs, tf.layers
are wrappers around tf.keras.layers. 根据官方文档,
tf.layers
是tf.layers
的包装。 For example , convolutional layers in Layers API inherit from tf.keras.layers
. 例如 ,Layers API中的卷积层继承自
tf.keras.layers
。
@tf_export('layers.Conv1D')
class Conv1D(keras_layers.Conv1D, base.Layer):
"""1D convolution layer (e.g. temporal convolution).
Even more so, Layers API is deprecated and will be removed from TF 2.0. 更重要的是,不建议使用Layers API,并将其从TF 2.0中删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.