张小白的体验官日记2——“图像消消消”案例体验
在9月份的时候,张小白曾经当过首次昇腾的体验官,曾经发了一篇博客:《张小白的昇腾体验官日记》 https://bbs.huaweicloud.com/blogs/300351
讲诉的是如何使用CANN完成ResNet50网络的图片分类,当时好像最后拿了200元俸禄(当官的收入叫做俸禄)
结果第二期的时候,张小白因故没有参加,谁知道俸禄提高到了400元。这可把张小白心疼的。。。
这不,有了第三次的体验官活动(活动链接:https://developer.huaweicloud.com/signup/00feb88d4a9845c8a426c40f1ccf026e)后,张小白心想:怎么也不能再错过了。。
活动帖:
https://bbs.huaweicloud.com/forum/forum.php?mod=viewthread&tid=164772
任务1:
1.“图像消消消”应用案例(点击体验):https://www.hiascend.com/zh/developer/mindx-sdk/imageInpainting?fromPage=1
打开链接进入juputer环境。阅读全文并进行操作即可。
从上面的意思看,很像CANN训练营MindX SDK的作业题。 要抠掉一个人,就需要先找到这个人,然后把他抹去。
看模型网络结构:
先由粗糙网络Coarse network,产生粗略的缺失内容(图像的大体轮廓),然后由精细网络对改内容进行精细修复。
其实可以无脑做题目,但是个人建议还是仔细看一遍再做。。。
做完以后,截图提交回复专用贴即可:
任务2:
通过申请云资源,用户下载案例的开源代码,在自己的环境上真实完成案例复现,输出体验报告,将链接提交在【任务二成果提交专用帖】上,可赢取奖励。
张小白CANN训练营里面有个云服务器还活着。。。
这个服务器的建立过程参见:https://bbs.huaweicloud.com/forum/thread-162450-1-1.html
此处不再赘述。
来干活吧:
打开 https://github.com/Atlas200dk/sample-imageinpainting-HiFill/tree/master/Huawei_Ascend
看一下所需要的环境信息:
开机:
登陆:
鉴于github没法打开:
https://github.com/Atlas200dk/sample-imageinpainting-HiFill.git
可以借助于gitee过渡一下:
https://gitee.com/zhanghui_china/sample-imageinpainting-HiFill/
下载样例代码:
git clone https://gitee.com/ascend/samples.git
cd ~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill
获取单算子json文件:
wget https://c7xcode.obs.myhuaweicloud.com/models/imageinpainting_hifill/hifill.pb --no-check-certificate
将下载的tf模型(pb)转成om离线模型:
单算子:
atc --singleop=./matmul_27648.json --output=./0_BatchMatMul_0_0_1_1_1024_1024_0_0_1_1_1024_27648_0_0_1_1_1024_27648 --soc_version=Ascend310 atc --output_type=FP32 --input_shape="img:1,512,512,3;mask:1,512,512,1" --input_format=NHWC --output="./hifill" --soc_version=Ascend310 --framework=3 --save_original_model=false --model="./hifill.pb"
cp ./hifill/0_BatchMatMul_0_0_1_1_1024_1024_0_0_1_1_1024_27648_0_0_1_1_1024_27648.om ./model/
hifill模型:
atc --model=hifill.pb --framework=3 --output=./hifill --soc_version=Ascend310
cp hifill.om ./model/
cd data
获取测试图片:
wget https://c7xcode.obs.myhuaweicloud.com/models/imageinpainting_hifill/data/test.jpg --no-check-certificate
cd mask
获取掩码图片:
wget https://c7xcode.obs.myhuaweicloud.com/models/imageinpainting_hifill/mask/test.jpg --no-check-certificate
安装pip
sudo apt-get install python3-pip
果然出现了dpkg错误:
根据提示,参考FAQ解决:
sudo mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/
sudo mkdir /var/lib/dpkg/info/
sudo apt-get update
sudo apt-get -f install
sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old/
sudo rm -rf /var/lib/dpkg/info
sudo mv /var/lib/dpkg/info_old/ /var/lib/dpkg/info/
重来:
sudo apt-get install python3-pip
sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
。。。
python3.6 -m pip install --upgrade pip --user -i https://mirrors.huaweicloud.com/repository/pypi/simple
python3.6 -m pip install Cython numpy pillow tornado==5.1.0 protobuf --user -i https://mirrors.huaweicloud.com/repository/pypi/simple
sudo apt-get install python3-opencv
。。。
python atlasutil库依赖pyav, numpy和PIL
先安装ffmpeg
wget http://www.ffmpeg.org/releases/ffmpeg-4.1.3.tar.gz
tar -zxvf ffmpeg-4.1.3.tar.gz
cd ffmpeg-4.1.3
./configure --enable-shared --enable-pic --enable-static --disable-x86asm --prefix=/home/HwHiAiUser/ascend_ddk/x86
...
make -j8
...
make install
...
vim /etc/ld.so.conf.d/ffmpeg.conf
增加一行:
/home/HwHiAiUser/ascend_ddk/x86/lib
ldconfig
vim /etc/profile
增加一行:
export PATH=$PATH:/home/HwHiAiUser/ascend_ddk/x86/bin
source /etc/profile
cp /home/HwHiAiUser/ascend_ddk/x86/lib/pkgconfig/* /usr/share/pkgconfig
apt-get install pkg-config libxcb-shm0-dev libxcb-xfixes0-dev
。。。
源码安装pyav
git clone https://gitee.com/mirrors/PyAV.git
cd PyAV
python3.6 setup.py build --ffmpeg-dir=/home/HwHiAiUser/ascend_ddk/x86
...
python3.6 setup.py install
...
验证:
pip3.6 install numpy
pip3.6 install Pillow
安装python atlasutil库:
vi ~/.bashrc
增加:
export PYTHONPATH=$HOME/samples/python/common/:$PYTHONPATH
source ~/.bashrc
cd ~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill
cd src
执行消消乐:
python3.6 main.py
好像acl还是不行。。。No module named 'acl'
发了个贴
https://bbs.huaweicloud.com/forum/forum.php?mod=viewthread&tid=173171
求助了一下,老师说是环境变量设置得不对。
根据老师的要求,设置环境变量:
export pyACL_install_path=/usr/local/Ascend/ascend-toolkit/latest
export PYTHONPATH="${pyACL_install_path}/pyACL/python/site-packages/acl:$PYTHONPATH"
export LD_LIBRARY_PATH=”${pyACL_install_path}/pyACL/python/site-packages:$LD_LIBRARY_PATH”
再验证一下:
没问题了。
那就准备开干了!
重跑:
贴一下结果:
root@ecs-zhanghui-china:~# cd ~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill
root@ecs-zhanghui-china:~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill# cd src
root@ecs-zhanghui-china:~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill/src# ls -lrt
total 12
-rw-r--r-- 1 root root 9722 Dec 12 22:48 main.py
root@ecs-zhanghui-china:~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill/src# python3.6 main.py
MODEL_MATMUL_PATH /root/samples/python/level2_simple_inference/6_other/imageinpainting_hifill/src/../model
init resource stage:
Init resource success
Init model resource start...
[AclLiteModel] create model output dataset:
malloc output 0, size 3145728
malloc output 1, size 4194304
malloc output 2, size 1048576
Create model output dataset success
Init model resource success
==========
in readimages, use time:0.27280282974243164
file: /root/samples/python/level2_simple_inference/6_other/imageinpainting_hifill/src/../data/test.jpg, shape= (3456, 5184, 3)
in pre_process, use time:0.24844908714294434
in inference, use time:0.11571073532104492
[SingleOp] batch_matmul run success
in matmul_om_large, use time:0.19054818153381348
in post_process, use time:1.0116896629333496
Execute end
acl resource release all resource
AclLiteModel release source success
acl resource release stream
acl resource release context
Reset acl device 0
Release acl resource success
in main, use time:3.7977166175842285
root@ecs-zhanghui-china:~/samples/python/level2_simple_inference/6_other/imageinpainting_hifill/src#
把几张图片都下载下来看看:
原图:
消消乐后的图:
还真的是精彩绝伦的消消乐。
再补上mask下的掩码图片:
额,这张图让张小白感官受到了一点刺激。。。
上面三张图分别来源于data, mask和out三个目录:
好了,这就算是验证成功了。可以交差了~~
心得体会:
1.遇到问题多去论坛提问,会有专家答疑解惑的;
2.安装过程要心细,不要错过任何环节。
3.对消消乐的模型算法有了进一步的理解。
4.昇腾还是很强大的。Ascend310在推理方面仍然是一流的。
(全文完,谢谢阅读)
- 点赞
- 收藏
- 关注作者
评论(0)