我想将下面的py手电筒网络(v1.2)更改为tensorflow。我在tf.keras.layers.Conv2D和tf.nn.conv2d之间感到困惑,我应该选择什么?
import torch.nn as nn
nn.Sequential(nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride=stride, padding=padding, dilation=dilation, bias=True),
nn.BatchNorm2d(out_planes),
nn.ReLU(inplace=True))
发布于 2019-10-23 18:56:12
tf.nn.conv2d
是函数式api,tf.keras.layers.Conv2D
是层类api.你应该用后一个。它与torch.nn.functional.conv2d
和torch.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())
https://stackoverflow.com/questions/58532977
复制