QAT aware training for mobilenetV2 not working
@Xhark 已经在做这个了。
开始于 2023年8月28日。
评估
这个 Issue 还没有评估数据。
描述
Hello I am trying to apply quantization aware training for mobilenet, and I am testing on the mnist dataset, the floating point models works very well but the moment I add the quantization I have a very huge loss and the model isn't converging.
definition of the model :
`
def build_model(target_size):
input_tensor = Input(shape=(target_size, target_size, 3))
base_model = applications.MobileNetV2(
include_top=False,
weights='imagenet',
input_tensor=input_tensor,
input_shape=(target_size, target_size, 3),
pooling='avg')
for layer in base_model.layers:
layer.trainable = False # trainable has to be false in order to freeze the layers
op = Dense(256, activation='relu')(base_model.output)
op = Dropout(.25)(op)
output_tensor = Dense(10, activation='softmax')(op)
model = Model(inputs=input_tensor, outputs=output_tensor)
return model`
quantization and training:
def quantized_model(model_fp32):
quantize_model = tfmot.quantization.keras.quantize_model
q_aware_model = quantize_model(model_fp32)
return q_aware_model
`q_aware_model = quantized_model(model_fp32)
q_aware_model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['categorical_accuracy'])
print("training model with int8 precision")
train_images_subset = train_images[0:1000] # out of 60000
train_labels_subset = train_labels[0:1000]
encoded_y_quant_train = to_categorical(train_labels_subset, num_classes=10, dtype='float32')
train_quant_generator = load_data_generator(train_images_subset, encoded_y_quant_train, batch_size=64)
q_aware_model.fit(train_quant_generator,
batch_size=500, epochs=1, steps_per_epoch=900)`
- 主要语言
- Python
- 星标
- 1.6k
- 派生
- 349
- 平均合并
- 3 天 2 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/model-optimization 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
tensorflow/model-optimization#1301 · 1 条评论 ·
-
bug
难度 4/5 3-5 天 新手友好度 48/100
tensorflow/model-optimization#1272 ·
-
bug
难度 3/5 1-2 天 新手友好度 50/100
tensorflow/model-optimization#1270 · 2 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 48/100
tensorflow/model-optimization#1241 ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
tensorflow/model-optimization#1182 · 1 条评论 ·
查看 tensorflow/model-optimization 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 86/100
browser-use/browser-use#5905 ·
-
type: enhancement
难度 2/5 1-3 小时 新手友好度 68/100
ynput/ayon-python-api#363 ·
-
bug needs triage
难度 2/5 1-3 小时 新手友好度 88/100
modelscope/FunASR#3728 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
open-compass/opencompass#2655 ·