AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-30064284

Shinobu HUYUGIRI's questions

Martin Hope
Shinobu HUYUGIRI
Asked: 2025-04-10 03:22:18 +0800 CST

如何将 Kaggle 上的 TensorFlow 1“BigGAN”模型转换为 TensorFlow Lite 格式?

  • 6

如何将 Kaggle 上的 TensorFlow 1“BigGAN”模型转换为 TensorFlow Lite 格式?

https://www.tensorflow.org/hub/tutorials/biggan_ Generation_with_tf_hub?hl=ja

我正在尝试实现以下源代码来定义 TensorFlow.Keras 模型并将其转换为 TensorFlow Lite 格式,但是当我尝试使用 hub.KerasLayer 创建的 Layer 在 Function API 中定义模型时,出现以下异常:

而且我也不知道如何指定 model.build() 的参数。

此模型需要多个输入,因此我无法使用该解决方案通过以下 URL 中显示的 Sequential API 构建模型。 如何保存输入形状为 (1, None, None, 3) 且 None 固定为 256 的模型?

有没有什么好的解决办法?

无法运行的源代码

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
from tensorflow.compat.v1 import keras
from tensorflow.compat.v1.keras import layers
import tensorflow_hub as hub

input_truncation = keras.Input(shape=(), name='truncation')
input_y = keras.Input(shape=(1000, ), name='y')
input_z = keras.Input(shape=(128, ), name='z')
hub_layer = hub.KerasLayer(
            "https://www.kaggle.com/models/deepmind/biggan/TensorFlow1/128/2",
            trainable=False,
            signature="default", 
            signature_outputs_as_dict=True,
            input_shape = [[], [1000], [128]],
            output_shape = [128, 128, 3],
        )

### -->> TypeError occur HERE
output = hub_layer([input_truncation, input_y, input_z])
### <<-- TypeError occur HERE

model = tf.keras.models.Model(inputs=[input_truncation, input_y, input_z], outputs=[output])

### -->> How to build this model 
model.build([1], [1, 1000], [1, 128])
### <<-- How to build this model

model.summary()
model.save("biggan-128")

converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

发生的异常

 TypeError
in user code:

    File "/home/shino/anaconda3/envs/movenet/lib/python3.10/site-packages/tensorflow_hub/keras_layer.py", line 242, in call  *
        result = f()

    TypeError: pruned(truncation, y, z) takes 0 positional arguments, got 1.
  File "/tmp/__autograph_generated_fileedgegq8b.py", line 74, in tf__call
    ag__.if_stmt(ag__.not_(ag__.ld(self)._has_training_argument), if_body_3, else_body_3, get_state_3, set_state_3, ('result', 'training'), 1)
  File "/tmp/__autograph_generated_fileedgegq8b.py", line 37, in if_body_3
    result = ag__.converted_call(ag__.ld(f), (), None, fscope)
TypeError: pruned(truncation, y, z) takes 0 positional arguments, got 1.

During handling of the above exception, another exception occurred:

  File "/tmp/__autograph_generated_fileedgegq8b.py", line 37, in if_body_3
    result = ag__.converted_call(ag__.ld(f), (), None, fscope)
  File "/tmp/__autograph_generated_fileedgegq8b.py", line 74, in tf__call
    ag__.if_stmt(ag__.not_(ag__.ld(self)._has_training_argument), if_body_3, else_body_3, get_state_3, set_state_3, ('result', 'training'), 1)
  File "/home/shino/sandbox/python/biggan/biggan_export.py", line 21, in <module>
    output = hub_layer([input_truncation, input_y, input_z])
TypeError: in user code:

    File "/home/shino/anaconda3/envs/movenet/lib/python3.10/site-packages/tensorflow_hub/keras_layer.py", line 242, in call  *
        result = f()

    TypeError: pruned(truncation, y, z) takes 0 positional arguments, got 1.

要求.txt

absl-py==2.2.1
astunparse==1.6.3
cachetools==5.5.2
certifi==2025.1.31
charset-normalizer==3.4.1
coloredlogs==15.0.1
flatbuffers==1.12
gast==0.4.0
google-auth==2.38.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.71.0
h5py==3.13.0
humanfriendly==10.0
idna==3.10
keras==2.9.0
Keras-Preprocessing==1.1.2
libclang==18.1.1
Markdown==3.7
MarkupSafe==3.0.2
mpmath==1.3.0
numpy==1.26.4
oauthlib==3.2.2
onnx==1.14.1
onnx-graphsurgeon==0.5.7
onnx2tf==1.26.9
onnxruntime==1.21.0
opt_einsum==3.4.0
packaging==24.2
protobuf==3.20.3
psutil==7.0.0
pyasn1==0.6.1
pyasn1_modules==0.4.2
requests==2.32.3
requests-oauthlib==2.0.0
rsa==4.9
six==1.17.0
sng4onnx==1.0.4
sympy==1.13.3
tensorboard==2.9.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.9.0
tensorflow-estimator==2.9.0
tensorflow-hub==0.16.1
tensorflow-io-gcs-filesystem==0.37.1
tensorflow-neuron==1.0
termcolor==3.0.0
tf-keras==2.14.1
tf2onnx==1.13.0
typing_extensions==4.13.0
urllib3==2.3.0
Werkzeug==3.1.3
wrapt==1.17.2
tensorflow
  • 1 个回答
  • 21 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve