Tensorflow 2 没有 fully_connected 函数 我该如何模拟它?

Tensorflow 2 does not have a a fully_connected function How can I simulate that?

我正在制作一个用于车道检测的 CNN 模型。但是 tensorflow 2 没有 tf.contrib 因此我无法访问 fully_connected 层。

如何制作自己的全连接层函数?

这是我目前的模型:

conv2d = tf.nn.conv2d
batch_norm = tf.nn.batch_normalization
dropout = tf.nn.dropout
max_pool = tf.nn.max_pool2d
softmax = tf.nn.softmax
relu = tf.nn.relu
avg_pool = tf.nn.avg_pool2d
checkpoint = tf.train.Checkpoint







def network(x):
    model = conv2d(x,filters=[1,5,5,1],strides=[1,2,2,1],padding='SAME')
    model = relu(model)
    model = batch_norm(model)
    model = max_pool(model)

    model = conv2d(model,filters=[1,4,4,1],strides=[1,2,2,1],padding='SAME')
    model = relu(model)
    model = batch_norm(model)
    model = max_pool(model)

    model = conv2d(model,filters=[1,3,3,1],strides=[1,2,2,1],padding='SAME')
    model = relu(model)
    model = batch_norm(model)
    model = avg_pool(model)

    model = dropout(model,0.3)
    # i want to add the fully connect layer here then a softmax layer then another fully connected


我认为您可能正在寻找的是 keras 模块中的 Dense 层 - https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense