Я использую этот код в приглашении anaconda, потому что я скачал библиотеку keras в окружение.
Код: Выделить всё
activate env
python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5
И я я собираюсь преобразовать этот файл h5 в файл tflite в блокноте Jupyter с помощью этого кода.
Код: Выделить всё
model = tf.keras.models.load_model("./yolo/yolo.h5", compile=False)
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
open("keras_model.tflite", "wb").write(tflite_model)
Код: Выделить всё
ValueError Traceback (most recent call last)
in ()
1 model = tf.keras.models.load_model("./yolo/yolo.h5", compile=False)
2 converter = tf.lite.TFLiteConverter.from_keras_model(model)
----> 3 tflite_model = converter.convert()
4 open("keras_model.tflite", "wb").write(tflite_model)
~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\lite\python\lite.py in convert(self)
426 raise ValueError(
427 "None is only supported in the 1st dimension. Tensor '{0}' has "
--> 428 "invalid shape '{1}'.".format(_get_tensor_name(tensor), shape_list))
429 elif shape_list and shape_list[0] is None:
430 # Set the batch size to 1 if undefined.
ValueError: None is only supported in the 1st dimension. Tensor 'input_1' has invalid shape '[None, None, None, 3]'.
наша модель сводка:
Модель: "model_1"
Слой (тип) Параметр выходной формы № подключен к
input_1 (InputLayer) [(Нет, Нет, Нет, 0
conv2d_1 (Conv2D) (Нет, Нет, Нет, 3 864 input_1[0][0]
batch_normalization_1 (BatchNor (Нет, Нет, Нет, 3 128 conv2d_1[0][0]
leaky_re_lu_1 (LeakyReLU) (Нет, Нет, Нет, 3 0atch_normalization_1[ 0][0]
zero_padding2d_1 (ZeroPadding2D (Нет, Нет, Нет, 3 0leaky_re_lu_1[0][0]
conv2d_2 (Conv2D) (Нет, Нет, Нет , 6 18432 Zero_padding2d_1[0][0]
batch_normalization_2 (BatchNor (Нет, Нет, Нет, 6 256 conv2d_2[0][0]
leaky_re_lu_2 (LeakyReLU) (Нет, Нет, Нет, 6 0atch_normalization_2[0][0]
conv2d_3 (Conv2D) (Нет, Нет, Нет, 3 2048leaky_re_lu_2[0][0]
.
..
.
batch_normalization_65 (BatchNo (Нет, Нет, Нет, 5 2048 conv2d_66[0][0]
batch_normalization_72 (BatchNo (Нет, Нет, Нет, 2 1024 conv2d_74[0] [0]
leaky_re_lu_58 (LeakyReLU) (Нет, Нет, Нет, 1 0atch_normalization_58[0][0]
leaky_re_lu_65 (LeakyReLU) (Нет, Нет, Нет, 5 0 Batch_normalization_65[0][0]
leaky_re_lu_72 (LeakyReLU) (Нет, Нет, Нет, 2 0atch_normalization_72[0][0]
conv2d_59 (Conv2D) (Нет, Нет, Нет, 2 261375leaky_re_lu_58[0][0]
conv2d_67 (Conv2D) (Нет, Нет, Нет, 2 130815leaky_re_lu_65[0][0]
conv2d_75 (Conv2D) (Нет, Нет, Нет, 2 65535leaky_re_lu_72[0][0]
Итого параметры: 62 001 757
Обучаемые параметры: 61 949 149
Необучаемые параметры: 52 608
Подробнее здесь: https://stackoverflow.com/questions/615 ... flite-file
Мобильная версия