bubbliiiing / mobilenet-yolov4-tf2

这是一个mobilenet-yolov4的库,把yolov4主干网络修改成了mobilenet,修改了Panet的卷积组成,使参数量大幅度缩小。
MIT License
47 stars 26 forks source link

博主我在训练完成后,将h5权重转化成tflite失败了 #4

Open RMsu233 opened 1 year ago

RMsu233 commented 1 year ago

环境:

numpy==1.18.4
matplotlib==3.2.1
opencv_python==4.2.0.34
tensorflow_gpu==2.2.0
tqdm==4.46.1
Pillow==8.2.0
h5py==2.10.0

转换代码:

import tensorflow as tf

#加载模型
model = tf.keras.models.load_model('best_epoch_weights.h5')

#转换为TFLite模型
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.allow_custom_ops = True  # 允许自定义操作
tflite_model = converter.convert()

保存TFLite模型
with open('yolov4.tflite', 'wb') as f:
    f.write(tflite_model)

报错信息:

Traceback (most recent call last): File "h5py/h5t.pxd", line 14, in init h5py._conv File "h5py/h5t.pyx", line 293, in init h5py.h5t File "/home/rmsu233/anaconda3/envs/Tensorflow/lib/python3.8/site-packages/numpy/init.py", line 320, in getattr raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'typeDict'

bubbliiiing commented 1 year ago

存下来的权值没有结构的

RMsu233 commented 1 year ago

存下来的权值没有结构的

我应该修改训练的部分对吗

bubbliiiing commented 1 year ago

不知能不能直接保存带结构的模型

RMsu233 commented 1 year ago

您好,我将带结构的模型保存到本地了,但在转换模型时出现了错误 该错误似乎是由 mobilenet_v3.py 文件中 hard_swish 激活函数未知 导致的层错误

def hard_sigmoid(x):
    return backend.relu(x + 3.0, max_value=6.0) / 6.0

def hard_swish(x):
    return Multiply()([Activation(hard_sigmoid)(x), x])

def _make_divisible(v, divisor=8, min_value=None):
    if min_value is None:
        min_value = divisor
    new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
    # Make sure that round down does not go down by more than 10%.
    if new_v < 0.9 * v:
        new_v += divisor
    return new_v

报错信息: ValueError: Unknown activation function: hard_swish. Please ensure this object is passed to the custom_objects argument.


您有什么解决办法吗