TF2 训练自己的模型并导出模型转为TFlite 格式主要命令

9 篇文章 1 订阅
8 篇文章 0 订阅

1.使用 labelImg 标注物体,产生 .xml 文件命令:

python labelImg.py

2.将物体 .xml 文件转换成 .csv文件命令:

python xml_to_csv.py

3.将test_images\train 全部拷贝到data 路径下(有两个.csv 文件):

将.cvs 文件转换成.record文件命令:

python generate_tfrecord.py --csv_input=data/cup_train.csv --output_path=data/cup_train.record
python generate_tfrecord.py --csv_input=data/cup_test.csv --output_path=data/cup_test.record

4.开始训练数据命令:

python model_main_tf2.py -pipeline_config_path=training/ssd_mobilenet_v2_320x320_coco17_tpu-8.config --model_dir=training  --alsologtostderr

5.可视化训练模型命令:

tensorboard --logdir training --bind_all

6.导出训练模型命令:

python exporter_main_v2.py --input_type  image_tensor  --pipeline_config_path=training/ssd_mobilenet_v2_320x320_coco17_tpu-8.config --trained_checkpoint_dir=training --output_directory=training/train_export

7.打开测试程序命令:

jupyter notebook

8.导出 tflite 文件命令:

#tensorflow1.x
python2 export_tflite_ssd_graph.py --pipeline_config_path ssd_mobilenet_v1_coco_2018_01_28/pipeline.config --trained_checkpoint_prefix ssd_mobilenet_v1_coco_2018_01_28/model.ckpt --output_directory ssd_mobilenet_v1_coco_2018_01_28/

#tensorflow2.0
python3 export_tflite_graph_tf2.py --pipeline_config_path=training_tf2/ssd_mobilenet_v2_320x320_coco17_tpu-8.config     --trained_checkpoint_dir=training_tf2/ --output_directory=training_tf2/train_export


python3 export_tflite_model_tf2.py \
    --pipeline_config_path training_tf2/ssd_mobilenet_v2_320x320_coco17_tpu-8.config \
    --trained_checkpoint_dir training_tf2 \
    --output_directory training_tf2/train_export \
    --keypoint_label_map_path training_tf2/train_export/label_cup.txt \
    --max_detections 10 \
    --centernet_include_keypoints true \
    --config_override " \
            model{ \
              center_net { \
                image_resizer { \
                  fixed_shape_resizer { \
                    height: 320 \
                    width: 320 \
                  } \
                } \
              } \
            }" \

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TensorFlow是一个广泛用于机器学习和深度学习的开源框架。它提供了许多功能强大的工具和接口,使得加载和解析tflite模型变得相对简单。 要加载和解析tflite模型,首先需要使用TensorFlow提供的tflite模块。我们可以使用以下代码导入tflite模块: ``` import tensorflow as tf interpreter = tf.lite.Interpreter(model_path="model.tflite") interpreter.allocate_tensors() ``` 在上述代码中,我们首先导入tensorflow模块,并创建了一个tf.lite.Interpreter对象。通过指定模型的路径"model.tflite",我们将tflite模型加载到内存中。然后,我们使用interpreter对象的allocate_tensors方法来为模型分配所需的张量。 加载完成后,可以使用interpreter对象的get_input_details和get_output_details方法获取模型的输入和输出张量的详细信息: ``` input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() ``` 通过打印input_details和output_details,我们可以获得输入和输出张量的名称、形状、数据类型等详细信息。 接下来,我们可以准备要输入模型的数据,并将其设置为输入张量的值: ``` input_data = ... interpreter.set_tensor(input_details[0]['index'], input_data) ``` 在上述代码中,我们将input_data设置为我们要输入模型的数据,并使用interpreter对象的set_tensor方法将其设置为输入张量的值。input_details[0]['index']表示输入张量的索引。 然后,我们可以使用interpreter对象的invoke方法来运行模型: ``` interpreter.invoke() ``` 运行模型后,我们可以通过获取输出张量的值来获取模型的预测结果: ``` output_data = interpreter.get_tensor(output_details[0]['index']) ``` 将output_data打印出来,我们可以获得模型的预测结果。 总结起来,使用TensorFlow加载和解析tflite模型的步骤包括:导入tflite模块、创建Interpreter对象并加载tflite模型、获取输入和输出张量的详细信息、设置输入张量的值、运行模型并获取输出张量的值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值