如何将以下代码从pytorch更改为tensorflow?

时间:2019-10-24 01:38:24

标签: tensorflow pytorch

我想将Follow pytorch网络(v1.2)更​​改为tensorflow。我在 tf.nn.conv2d tf.keras.layers.Conv2D 之间感到困惑,我该选择什么?

import firebase from 'firebase';
import 'firebase/app';
import 'firebase/firestore'
import 'firebase/auth';



const config = { /* COPY THE ACTUAL CONFIG FROM FIREBASE CONSOLE */
    (there is my api info)
};
const fire = firebase.initializeApp(config);
export default fire;

1 个答案:

答案 0 :(得分:3)

tf.nn.conv2d是功能性api,tf.keras.layers.Conv2D是层级api。您应该使用后一种。它与torch.nn.functional.conv2dtorch.nn.Conv2D之间的关系非常相似。

import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Conv2D, ReLU, BatchNormalization

model = Sequential()
model.add(Conv2D(filters=10, kernel_size=3, strides=1))
model.add(BatchNormalization())
model.add(ReLU())