我想知道在 Tensorflow 2 的量化感知训练期间模拟 BatchNorm 折叠的当前可用选项是什么。 Tensorflow 1 具有tf.contrib.quantize.create_training_graph将 FakeQuantization 层插入图中并负责模拟批量归一化折叠的功能(根据本白皮书)。
Tensorflow 2 有一个关于如何在他们最近采用的API 中使用量化的教程tf.keras,但他们没有提到关于批量标准化的任何内容。我使用 BatchNorm 层尝试了以下简单示例:
import tensorflow_model_optimization as tfmo
model = tf.keras.Sequential([
l.Conv2D(32, 5, padding='same', activation='relu', input_shape=input_shape),
l.MaxPooling2D((2, 2), (2, 2), padding='same'),
l.Conv2D(64, 5, padding='same', activation='relu'),
l.BatchNormalization(), # BN!
l.MaxPooling2D((2, 2), (2, 2), padding='same'),
l.Flatten(),
l.Dense(1024, activation='relu'),
l.Dropout(0.4),
l.Dense(num_classes),
l.Softmax(),
])
model = tfmo.quantization.keras.quantize_model(model)
Run Code Online (Sandbox Code Playgroud)
然而,它给出了以下例外:
RuntimeError: Layer batch_normalization:<class 'tensorflow.python.keras.layers.normalization.BatchNormalization'> is not supported. You can quantize this layer by passing a `tfmot.quantization.keras.QuantizeConfig` …Run Code Online (Sandbox Code Playgroud) python tensorflow batch-normalization tensorflow2.0 quantization-aware-training
我正在尝试使用scons将源目录中的一些头文件复制到我的构建目录中的'includes'目录.我的目标是一个静态库,我想将它与相关的标题一起分发.预期的最终结果:
build
|-- objects -> .o output files for constructing libmclib.a
|-- includes
| |-- foo.h
| `-- bar.h
`-- libmclib.a
Run Code Online (Sandbox Code Playgroud)
我的SConstruct:
#!python
target = 'mock'
env = Environment(LINKCOM = "$LINK -o $TARGET $SOURCES $LINKFLAGS $CCFLAGS")
Export('env', 'target')
build_base = 'build'
SConscript('SConscript', variant_dir=build_base, duplicate=0)
# remove build directory
if GetOption('clean'):
import subprocess
subprocess.call(['rm', '-rf', build_base])
Run Code Online (Sandbox Code Playgroud)
我的SConscript:
#!python
Import('env')
# ...
# other stuff to build 'mclib_target'
# ...
def copy_header_files(target, source, env):
Mkdir(target)
header_files = []
for d in env['CPPPATH']: …Run Code Online (Sandbox Code Playgroud)