如何在TensorFlow中创建Inception模块

查看TensorFlow页面:https://github.com/tensorflow/models/tree/master/inception

他们展示了一张包含其架构的图片,特别是他们的’Inception’模块,这些模块并行包含:

  • 1×1的卷积层
  • 3×3的卷积层
  • 5×5的卷积层
  • 平均池化 + 1×1卷积

随后是一个’concat’层。

enter image description here

如何在TensorFlow中创建这个模块?

我想我可以这样做来创建并行操作:

start_layer = input_datafilter = tf.Variable(tf.truncated_normal([1,1,channels,filter_count], stddev=0.1)one_by_one = tf.nn.conv2d(start_layer, filter, strides=[1,1,1,1], padding='SAME')filter = tf.Variable(tf.truncated_normal([3,3,channels,filter_count], stddev=0.1)three_by_three = tf.nn.conv2d(start_layer, filter, strides=[1,1,1,1], padding='SAME')filter = tf.Variable(tf.truncated_normal([5,5,channels,filter_count], stddev=0.1)five_by_five = tf.nn.conv2d(start_layer, filter, strides=[1,1,1,1], padding='SAME')filter = tf.Variable(tf.truncated_normal([1,1,channels,filter_count], stddev=0.1)pooling = tf.nn.avg_pool(start_layer, filter, strides=[1,2,2,1], padding='SAME')filter = tf.Variable(tf.truncated_normal([1,1,channels,filter_count], stddev=0.1)pooling = tf.nn.conv2d(pooling, filter, strides=[1,1,1,1], padding='SAME')#connect one_by_one, three_by_three, five_by_five, pooling into an concat layer

但是,我如何将这四个操作合并到一个concat层中呢?


回答:

我做了与你非常相似的事情,然后用tf.concat()完成了。请注意axis=3,它与我的4D张量匹配,并在第四维度(索引3)上进行拼接。相关文档在这里:这里

我的最终代码大致如下:

def inception2d(x, in_channels, filter_count):    # 偏置维度 = 3*filter_count,然后是平均池化所需的额外in_channels    bias = tf.Variable(tf.truncated_normal([3*filter_count + in_channels], mu, sigma)),    # 1x1    one_filter = tf.Variable(tf.truncated_normal([1, 1, in_channels, filter_count], mu, sigma))    one_by_one = tf.nn.conv2d(x, one_filter, strides=[1, 1, 1, 1], padding='SAME')    # 3x3    three_filter = tf.Variable(tf.truncated_normal([3, 3, in_channels, filter_count], mu, sigma))    three_by_three = tf.nn.conv2d(x, three_filter, strides=[1, 1, 1, 1], padding='SAME')    # 5x5    five_filter = tf.Variable(tf.truncated_normal([5, 5, in_channels, filter_count], mu, sigma))    five_by_five = tf.nn.conv2d(x, five_filter, strides=[1, 1, 1, 1], padding='SAME')    # 平均池化    pooling = tf.nn.avg_pool(x, ksize=[1, 3, 3, 1], strides=[1, 1, 1, 1], padding='SAME')    x = tf.concat([one_by_one, three_by_three, five_by_five, pooling], axis=3)  # 在第四维度上拼接    x = tf.nn.bias_add(x, bias)    return tf.nn.relu(x)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注