当前位置:网站首页>Use the x2mindspire tool of mindstudio to convert training scripts
Use the x2mindspire tool of mindstudio to convert training scripts
2022-07-23 10:25:00 【Flower boy】
One 、 Reference material
X2MindSpore Function is introduced
Two 、 Related introduction
X2MindSpore The script conversion tool can convert PyTorch Scripts and TensorFlow 2.x The script is converted to MindSpore Code .
2.1 Important note
Currently only supported PyTorch and TensorFlow 2.x Training script conversion .
3、 ... and 、 Key steps
This article takes TensorFlow Version of FCN The model, for example .
3.1 Download the source code
Download link :FCN
Blogger's code :https://gitee.com/lljyoyo1995/fcn
3.2 Prepare the dataset
download VOC Data sets
$ wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
$ wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
$ wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
Decompress and organize the data set
VOC # path: /home/yang/dataset/VOC
├── test
| └──VOCdevkit
| └──VOC2007 (from VOCtest_06-Nov-2007.tar)
└── train
└──VOCdevkit
└──VOC2007 (from VOCtrainval_06-Nov-2007.tar)
└──VOC2012 (from VOCtrainval_11-May-2012.tar)
3.3 Generate txt Mark the file
python parser_voc.py --voc_path /PATH/TO/VOC
3.4 Modify source code
parser_voc.py Used in scipy.misc.imread Method is scipy 1.2.0 The old version before API,mindspore Minimum compatibility scipy 1.5.2, So please use scipy Recommended in the official deprecation warning of imageio.imread.
terms of settlement :
1. install imageio
pip install imageio
2. modify parser_voc.py Source code
label_image = np.array(misc.imread(label_path))
Change it to
label_image = np.array(imageio.imread(label_path))
3.5 Local runthrough code
If in TensorFlow 1.X Run... Under version , Please turn on emergency execution :
import tensorflow as tf
tf.enable_eager_execution()
Pull up training
python train.py

Reasoning test
python test.py

3.6 Framework Trans
Prerequisite : After running through the code , To carry out Framework Trans operation .
Install dependency packages
#pandas The version number must be greater than or equal to 1.2.4
pip3 install pandas
pip3 install libcst
Perform conversion
cd Ascend-cann-toolkit The installation directory /ascend-toolkit/{
version}/{
arch}-linux/toolkit/tools/x2mindspore/
./run_x2mindspore.sh -i Original script path -o Script conversion result output path -f The framework of the original script
Four 、TensorFlow GPU2Ascend
4.1 Set up Remote CANN

restart MindStudio Activate CANN
Set up the success 

4.2 Set up TensorFlow GPU2Ascend

# CANN Machine
[email protected]:32542
# Command File
/home/ma-user/Ascend/tfplugin/5.0.3/python/site-packages/npu_bridge/convert_tf2npu/main.py
# Input Paht
\PATH\TO\TensorFlow2.0-Examples\5-Image_Segmentation\FCN
# Output Path
\PATH\TO\TensorFlow2.0-Examples\5-Image_Segmentation

determine yes
5、 ... and 、FAQ
Q: Set up Remote CANN Failure

The reason for the error :
The remote server is not installed ascend-toolkit development tool
Solution 1 :
install ascend-toolkit development tool
Solution 2 :
Find one installed ascend-toolkit Server for
Q:TensorFlow Inconsistent versions lead to training errors
tensorflow.python.framework.errors_impl.InvalidArgumentError: Can not squeeze dim[2], expected a dimension of 1, got 224
[[{
{
node metrics/acc/Squeeze}}]]
result = visual_result(x[0], pred_label[0].numpy())
AttributeError: 'Tensor' object has no attribute 'numpy'
The reason for the error :
Source code support TF2.X, But the blogger's environment is TF1.X
Solution 1 :
stay TF2.X Running in the environment
Solution 2 :
stay TF1.X Running in the environment , Emergency execution needs to be started
import tensorflow as tf
tf.enable_eager_execution()
Q:h5py Inconsistent versions lead to reasoning errors
Report errors :original_keras_version = f.attrs[‘keras_version‘].decode(‘utf8‘) And problem solving
original_keras_version = f.attrs['keras_version'].decode('utf8')
AttributeError: 'str' object has no attribute 'decode'
The reason for the error :
In the installation tensorflow when , Default installation h5py by 3.1.0, The error is because you installed TF An overly high version of..., is not supported h5py.
terms of settlement :
uninstall h5py3.1.0 edition , install h5py2.10.0 edition
pip install h5py==2.10.0
Q: Training stuck

The reason for the error :
use parser_voc.py Generated train_image.txt The image path in is wrong
terms of settlement :
\ The backslash
Change to
/ Slash

Q: The lack of libcst

The reason for the error :
The lack of libcst rely on
terms of settlement :
install libcst
pip3 install libcst
Q: The lack of X2MindSpore Tools

The reason for the error :
Missing in server X2MindSpore Tools
terms of settlement :
install X2MindSpore Tools
边栏推荐
- Deeply understand mvcc and bufferpool caching mechanism
- EasyCVR平台升级到最新版本v2.5.0,如何同步mysql数据库?
- Qt报错:错误 C2039 “Value“: 不是 “`global namespace‘“ 的成员
- [circular statement]
- Langue C - quelques exercices classiques de langue C
- 客户至上 | 国产BI领跑者,思迈特软件完成C轮融资
- EasyCVR平台CGO回放回调参数缺失导致设备录像无法播放,该如何解决?
- Sum of three numbers: (sort + double pointer + pruning)
- Underlying mechanism of pointer
- [c#] IEnumerable可枚举类型接口分析yield
猜你喜欢

Anaconda source change and opencv installation

MySQL基础篇(运算符、排序分页、多表查询、函数)

在线问题反馈模块实战(十一):实现图片下载功能

Three goals and eight tasks of intelligent construction pilot city notice

error MSB4181: “QtRunWork”任务返回了 false,但未记录错误

L-cysteine modified gold nanoparticles (Cys GNPs) and bovine serum albumin / biotinylated albumin nanoparticles

Error msb4181: the "qtrunwork" task returned false, but no error was recorded

Qt报错:错误 C2039 “Value“: 不是 “`global namespace‘“ 的成员

31-spark的算子使用及调度流程

SSH超市进销存管理系统
随机推荐
Decompile the jar package / class file / modify the jar package using the decompile plug-in of idea
Illustration and text demonstrate the movable range of the applet movable view
金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(六))
"Lost wake up problem" in multithreading | why do wait() and notify() need to be used with the synchronized keyword?
【MySQL】游标「Cursor」
【学习笔记】图论思维题
隐适美invisAlign口扫转诊方式(导出口扫数据+线上问诊)
How to classify the same field values in a list under the same list
How does the browser import and export | delete bookmarks? Here are the steps
EasyCVR新版本(v2.5.0)目录分级功能如何使用?
Qt报错:错误 C2039 “Value“: 不是 “`global namespace‘“ 的成员
【C语言基础】16 可变数组(数组长度可扩展)
C语言——几道C语言经典习题
[C language foundation] 16 variable array (array length can be extended)
Anaconda source change and opencv installation
Normal form and anti normal form
金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(八))
宇视NVR设备接入EasyCVR平台,离线后无法上线该如何解决?
How to build and use redis fragment cluster
赛尔运维:高校IT运维服务新样本