Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

quantize_model() cannot detect a keras.Sequential model

未关闭
#1,144 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
keras, python, tensorflow

调研方向

首先,使用 TensorFlow 2.17.0、TensorFlow Model Optimization 0.8.0 以及从 load_model() 加载的模型重现报告的失败。阅读 quantize_model() 入口点及其对 Sequential 或 Functional 模型的检查。完成的标准是:接受从 .keras 文件加载的 keras.Sequential 模型,并为报告的案例提供回归测试覆盖。

由索引模型根据 Issue 内容生成。

描述

bug

Prior to filing: check that this should be a bug instead of a feature request. Everything supported, including the compatible versions of TensorFlow, is listed in the overview page of each technique. For example, the overview page of quantization-aware training is here. An issue for anything not supported should be a feature request.

Describe the bug
I'm passing a keras sequential model into quantize_model(), and I'm getting the error that the model isn't a sequential model.

System information

Carried out in:
Google Colab

TensorFlow version (installed from source or binary):
2.17.0

TensorFlow Model Optimization version (installed from source or binary):
0.8.0

Python version:
3.10.12

Describe the expected behavior
prepare a keras sequential model built from scratch that was imported via load_model()

Describe the current behavior
ValueError: to_quantize can only either be a keras Sequential or Functional model.

Code to reproduce the issue
!pip install tensorflow_model_optimization

import pandas as pd
import numpy as np
import time
import tensorflow as tf
import os
import tempfile
import keras
import tensorflow_model_optimization as tfmot
from google.colab import drive
from tensorflow.keras.models import load_model

drive.mount('/content/drive')
%cd /content/drive/My Drive/CS528/HW3

model = load_model('/content/drive/My Drive/CS528/HW3/q1_model.keras')

quant_aware_model_tflite = '/content/drive/My Drive/CS528/HW3/s_mnist_quant_aware_training.tflite'
quantize_model = tfmot.quantization.keras.quantize_model
q_aware_model = quantize_model(model)

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
I've already checked the same compound conditional using the imported model just before calling quantize_model(), and it behaves as it should. Only when quantize_model() is actually handling the model does it seem to think the model isn't a tf.keras.Sequential object.

主要语言
Python
星标
1.6k
派生
349
平均合并
3 天 2 小时
30 天内合并 PR
1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tensorflow/model-optimization 的其他 Issue

查看 tensorflow/model-optimization 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。