0

我想在嵌入式系统(Coral USB 加速器)上运行移动网络来分析我转换为频谱图的录音。我已经根据Tensorflow中的Mobile Net 论文实现了该模型。

def SeparableConv(x, num_filters, strides, alpha=1.0):
    x = tf.keras.layers.DepthwiseConv2D(kernel_size=3, padding='same')(x)
    x = tf.keras.layers.BatchNormalization()(x) 
    x = tf.keras.layers.ReLU()(x)
    x = tf.keras.layers.Conv2D(np.floor( num_filters * alpha), kernel_size=(1, 1), strides=strides, use_bias=False, padding='same')(x) 
    x = tf.keras.layers.BatchNormalization()(x)
    x = tf.keras.layers.ReLU()(x)
    return x 


def Conv(x, num_filters, kernel_size, strides=1, alpha=1.0):
    x = tf.keras.layers.Conv2D((np.floor( num_filters * alpha)), kernel_size=kernel_size, strides=strides, use_bias=False , padding='same')(x)
    x = tf.keras.layers.BatchNormalization()(x)
    x = tf.keras.layers.Activation('relu')(x)
    x = tf.keras.layers.ReLU()(x)
    return x

inputs = tf.keras.layers.Input(shape=(64, 64, 1))

x = Conv(inputs, num_filters=16, kernel_size=3 , strides=2)
x = SeparableConv(x, num_filters=32, strides=1)
x = SeparableConv(x, num_filters=64, strides=2)
x = SeparableConv(x, num_filters=64, strides=1)
x = SeparableConv(x, num_filters=128, strides=2)
x = SeparableConv(x, num_filters=128, strides=1)
x = SeparableConv(x, num_filters=256, strides=1)
x = SeparableConv(x, num_filters=256, strides=2)
x = SeparableConv(x, num_filters=256, strides=1)
x = SeparableConv(x, num_filters=256, strides=1)
x = SeparableConv(x, num_filters=256, strides=1)
x = SeparableConv(x, num_filters=256, strides=1)
x = SeparableConv(x, num_filters=512, strides=2)
x = SeparableConv(x, num_filters=512, strides=1)

x = tf.keras.layers.GlobalAveragePooling2D()(x)
x = tf.keras.layers.Dense(512)(x)
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Dropout(0.001)(x)
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Dense(2)(x)

outputs = tf.keras.layers.ReLU()(x)
model = tf.keras.models.Model(inputs, outputs)

要在 Coral USB 加速器上运行它,我需要对其进行量化并将其转换为 TensorFlow Lite 模型(然后使用 Edge TPU 编译器再次编译它)。但在从 32 位浮点数量化到 8 位整数后,预测会变得更糟。问题似乎是批量标准化keras.layers.BatchNormalization()。这不是 TensorFlow lite 中允许的指令。但是由于 Mobile Net 是专门为嵌入式系统设计的,而 Batch Normalization 是其中的基础部分,我无法想象这在 Edge TPU 上是不可能的。所以我想问一下是否有人知道获得 Mobile Net 的解决方法,特别是在 Coral USB 加速器上工作的批量标准化?

非常感谢您提前提供的帮助和建议!

4

0 回答 0