我有一个TF CNN模型,现在我想与此一起使用张量流的权重修剪API,但是我在网上检查的所有示例均仅适用于Keras模型
我想修剪现有模型的重量
def mnist_cnn(inputs):
input_layer = tf.reshape(inputs, [-1, 28, 28, 3])
# Convolutional Layer #1
conv1 = tf.layers.conv2d(
inputs=input_layer,
filters=32,
kernel_size=[5, 5],
padding="same",
activation=tf.nn.relu)
# Pooling Layer #1
pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2)
# Convolutional Layer #2 and Pooling Layer #2
conv2 = tf.layers.conv2d(
inputs=pool1,
filters=64,
kernel_size=[5, 5],
padding="same",
activation=tf.nn.relu)
pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2], strides=2)
# Dense Layer
pool2_flat = tf.reshape(pool2, [-1, 7 * 7 * 64])
dense = tf.layers.dense(inputs=pool2_flat, units=1024, activation=tf.nn.relu)
dropout = tf.layers.dropout(inputs=dense, rate=0.4)
# Logits Layer
outputs = tf.layers.dense(inputs=dropout, units=10)
return outputs
本教程定义了重量修剪 https://www.tensorflow.org/model_optimization/guide/pruning/pruning_with_keras
但是我不知道如何在现有模型中使用修剪API(而不将其升级为keras顺序模型)