您对华为云开发者网站的整体评价?

非常不满意 非常满意

0

1

2

3

4

5

6

7

8

9

10

*您遇到了哪些问题?(最多选三项)
*您感到满意的原因是?(最多选三项)
*请针对您所遇到的问题给出具体的反馈
200/200

Notebook
基于TensorFlow训练轻量化ssdlite_mbv2人脸手机检测模型
使用疲劳/分神驾驶样例数据集训练,可用于第18届挑战杯华为云赛道
HouYanSong
22个月以前
415KB 166 8
  • 许可证类型 ? Unknown
  • 标签
    图片目标检测TensorFlow-1.x目标检测TensorFlow
  • 资产ID 25d50ec5-3d4e-40de-bf6b-590c2bebd596

描述

训练ssdlite_mobilenet_v2_coco模型

本案例采用TensorFlow object_detection框架与疲劳/分神驾驶样例数据集数据集实现一个简单的人脸手机检测模型训练。

注意:本案例必须使用GPU运行,请查看《ModelArts JupyterLab 硬件规格使用指南》了解切换硬件规格的方法

安装TensorFlow object detection

import os
import moxing as mox
INFO:root:Using MoXing-v2.1.0.5d9c87c8-5d9c87c8
INFO:root:Using OBS-Python-SDK-3.20.9.1

拉取代码、配置环境

if not os.path.exists("object_detection.zip"):
    mox.file.copy("obs://houyansong/object_detection.zip", "object_detection.zip")
if not os.path.exists("object_detection"):
    os.system("unzip -q object_detection.zip")

首先通过conda创建一个python3.6的虚拟环境py36:

!/home/ma-user/anaconda3/bin/conda create -n py36 python=3.6.10 -y

接下来安装依赖包:

!/home/ma-user/anaconda3/envs/py36/bin/pip install ipykernel

添加kernel配置文件,使虚拟环境可以在notebook中被识别:

import json
import os

data = {
   "display_name": "Python36",
   "env": {
      "PATH": "/home/ma-user/anaconda3/envs/py36/bin:/home/ma-user/anaconda3/envs/python-3.7.10/bin:/modelarts/authoring/notebook-conda/bin:/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ma-user/modelarts/ma-cli/bin:/home/ma-user/modelarts/ma-cli/bin:/home/ma-user/anaconda3/envs/PyTorch-1.4/bin"
   },
   "language": "python",
   "argv": [
      "/home/ma-user/anaconda3/envs/py36/bin/python",
      "-m",
      "ipykernel",
      "-f",
      "{connection_file}"
   ]
}

if not os.path.exists("/home/ma-user/anaconda3/share/jupyter/kernels/py36/"):
    os.mkdir("/home/ma-user/anaconda3/share/jupyter/kernels/py36/")

with open('/home/ma-user/anaconda3/share/jupyter/kernels/py36/kernel.json', 'w') as f:
    json.dump(data, f, indent=4)
conda env list

选择该kernel(py36),验证一下python版本和pip版本:

!python -V
Python 3.6.10 :: Anaconda, Inc.
!pip -V
pip 21.2.2 from /home/ma-user/anaconda3/envs/py36/lib/python3.6/site-packages/pip (python 3.6)

安装TensorFlow

conda install tensorflow-gpu==1.15 -y

安装protobuf

conda install -c anaconda protobuf

安装object detection

%cd object_detection/models/research
/home/ma-user/work/object_detection/models/research
%ll

编译

!protoc object_detection/protos/*.proto --python_out=.

安装

!cp object_detection/packages/tf1/setup.py .
!python -m pip install --use-feature=2020-resolver .

验证

!python object_detection/builders/model_builder_tf1_test.py
%cd ../..
/home/ma-user/work/object_detection

训练

!python ./model_main.py --pipeline_config_path=./data/ssdlite_mobilenet_v2_coco.config  --model_dir=./my_model_dir    --num_train_steps=20000 --sample_1_of_n_eval_examples=1    --alsologtostderr

导出推理模型

!python ./export_inference_graph.py --input_type=image_tensor --pipeline_config_path=./data/ssdlite_mobilenet_v2_coco.config --trained_checkpoint_prefix=./my_model_dir/model.ckpt-20000  --output_directory=./inference_model
import os
import moxing as mox
INFO:root:Using MoXing-v2.1.0.5d9c87c8-5d9c87c8
INFO:root:Using OBS-Python-SDK-3.20.9.1
mox.file.copy_parallel('object_detection/inference_model', 'obs://houyansong/inference_model')

交付

华为云ModelArts

华北-北京四

限制

公开

版本

版本号
版本ID
发布时间
发布状态
版本说明
1.0.0
1.0.0
2023-04-19 18:02
已完成
Initial release.

若您怀疑合法知识产权遭受侵犯,可以通过此链接进行投诉与建议。