Colorization自动着色

目录

1. 环境准备

2. 样例代码准备

3. 数据集准备

4. 训练

5. 推理


1. 环境准备

Colorization自动着色--我用的是x86,python:3.7.5,GPU机器, 安装的版本是mindspore版本是2.0.0-alpha

环境准备这一方面根据官网的操作步骤即可

MindSpore官网

机器准备

uname -a 

python

pip install mindspore==2.0.0-alpha

(murongmeng) root@ubuntu:/home/test_con/applications/Colorization/src# pip install mindspore==2.0.0-alpha 

Looking in indexes: http://mirrors.tools.huawei.com/pypi/simple/ 

Collecting mindspore==2.0.0-alpha 

  Downloading http://mirrors.tools.huawei.com/pypi/packages/41/dd/e0730c7c30c8fb358092a6f59f8189b70040e81898afbede8587324695ec/mindspore-2.0.0a0-cp37-cp37m-manylinux1_x86_64.whl (800.8 MB) 

     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 800.8/800.8 MB 1.2 MB/s eta 0:00:00 

Requirement already satisfied: asttokens>=2.0.4 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (2.0.5) 

Requirement already satisfied: scipy>=1.5.4 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (1.7.1) 

Requirement already satisfied: packaging>=20.0 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (20.1) 

Requirement already satisfied: protobuf>=3.13.0 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (3.13.0) 

Requirement already satisfied: pillow>=6.2.0 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (9.4.0) 

Requirement already satisfied: numpy>=1.17.0 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (1.21.5) 

Requirement already satisfied: astunparse>=1.6.3 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (1.6.3) 

Requirement already satisfied: psutil>=5.6.1 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from mindspore==2.0.0-alpha) (5.9.0) 

Requirement already satisfied: six in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from asttokens>=2.0.4->mindspore==2.0.0-alpha) (1.15.0) 

Requirement already satisfied: wheel<1.0,>=0.23.0 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from astunparse>=1.6.3->mindspore==2.0.0-alpha) (0.37.1) 

Requirement already satisfied: pyparsing>=2.0.2 in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from packaging>=20.0->mindspore==2.0.0-alpha) (2.4.6) 

Requirement already satisfied: setuptools in /root/miniconda3/envs/murongmeng/lib/python3.7/site-packages (from protobuf>=3.13.0->mindspore==2.0.0-alpha) (58.0.4) 

Installing collected packages: mindspore 

Successfully installed mindspore-2.0.0a0 

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: ttps://pip.pypa.io/warnings/venv 

2. 样例代码准备

GitHub - mindspore-courses/applications

我下载的是master分支

训练和推理脚本在applications/Colorization/src 下面

数据集放在applications//Colorization 下面

3. 数据集准备

applications/Colorization at master · mindspore-courses/applications · GitHub

在Dataset 里面有ImageNet dataset点击即可获取数据集

4. 训练

cd applications/Colorization/src

运行脚本

python train.py --batch_size 32 --learning_rate 0.5e-4 --num_epochs 50

其他全部用得默认值

 默认值也是使用GPU,所以就不需要修改

默认使用的数据集是../dataset/train

训练完成后

在checkpoints里面生成训练好的ckpt, 在images生成一些训练文件

5. 推理

python infer.py --img_path ../dataset/val --infer_dirs ../dataset/output --ckpt_path ../checkpoints/net50_0.ckpt

推理后的图片在../dataset/output里面

查看一下图片

这个色上的不错,有一丢丢老照片的感觉

用给的ckpt进行推理

python infer.py --img_path ../dataset/val --infer_dirs ../dataset/output --ckpt_path ../checkpoints/Colorization_model.ckpt

(murongmeng) root@ubuntu:/home/test_con/applications/Colorization/src# python infer.py --img_path ../dataset/val --infer_dirs ../dataset/output --ckpt_path ../checkpoints/Colorization_mode.ckpt 

[WARNING] ME(8511:139936069764928,MainProcess):2023-04-08-18:48:57.585.435 [mindspore/train/serialization.py:928] For 'load_param_into_net', remove parameter prefix name: my_train_one_stepcell_for_net.net.model., continue to load. 

[WARNING] ME(8511:139936069764928,MainProcess):2023-04-08-18:48:57.587.920 [mindspore/train/serialization.py:928] For 'load_param_into_net', remove parameter prefix name: my_train_one_stepcell_for_net.network.net.model., continue to load. 

1300 

0it [00:00, ?it/s]out_max {140, 141, 142, 143, 144, 145, 157, 160, 161, 162, 163, 176, 177, 180, 181, 56, 57, 71, 73, 74, 75, 83, 84, 85, 86, 88, 89, 90, 99, 100, 105, 106, 107, 108, 119, 20, 121, 122, 123, 124, 125, 126} 

1it [00:22, 22.82s/it]out_max {160, 161, 136, 137, 140, 141, 142, 143, 144, 145, 120, 121, 122, 127, 125, 126, 159} 

2it [00:22,  9.50s/it]out_max {143, 144, 145, 147, 156, 157, 161, 162, 163, 164, 174, 176, 51, 181, 182, 183, 83, 105, 109, 110, 111, 120, 122, 123, 124, 125, 126} 

3it [00:23,  5.23s/it]out_max {134, 135, 136, 144, 146, 147, 69, 82, 84, 85, 217, 98, 99, 100, 107, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 127} 

4it [00:23,  3.23s/it]out_max {140, 141, 142, 143, 144, 158, 159, 160, 161, 162, 163, 164, 178, 179, 180, 181, 182, 183, 200, 201, 202, 203, 220, 221, 222, 223, 241, 242, 120, 121, 122} 

5it [00:23,  2.12s/it]out_max {140, 141, 142, 143, 144, 145, 146, 147, 158, 159, 160, 161, 162, 163, 164, 165, 179, 180, 181, 182, 183, 200, 201, 202, 203, 220, 120, 123, 124, 125, 127} 

6it [00:23,  1.46s/it]out_max {140, 141, 142, 143, 144, 158, 159, 160, 161, 177, 178, 198, 199, 90, 105, 106, 107, 120, 121, 122, 123, 124, 125} 

7it [00:23,  1.03s/it]out_max {140, 141, 142, 143, 144, 145, 158, 159, 160, 161, 162, 163, 178, 179, 181, 199, 119, 120, 121, 122, 123, 124} 

8it [00:23,  1.33it/s]out_max {128, 134, 139, 140, 141, 142, 143, 144, 150, 151, 157, 158, 159, 160, 161, 162, 163, 176, 177, 178, 179, 180, 181, 197, 198, 199, 201, 218, 219, 220, 239, 24, 120, 121, 122, 123, 124, 125, 126, 127} 

9it [00:24,  1.76it/s]out_max {140, 141, 142, 143, 144, 159, 160, 161, 162, 180, 201, 85, 107, 108, 119, 120, 121, 122, 123, 124, 125, 126} 

10it [00:24,  2.25it/s]out_max {128, 134, 135, 136, 137, 140, 141, 142, 151, 152, 153, 157, 158, 159, 160, 176, 177, 178, 179, 180, 197, 198, 199, 84, 219, 99, 100, 107, 116, 117, 118, 119 120, 121, 122, 125, 126} 

11it [00:24,  2.81it/s]out_max {139, 140, 141, 142, 143, 144, 157, 158, 159, 160, 161, 176, 177, 178, 197, 198, 199, 200, 201, 88, 89, 90, 91, 220, 219, 103, 104, 105, 106, 107, 108, 240, 41, 120, 121, 122, 123, 124, 125, 126} 

12it [00:24,  3.37it/s]out_max {261, 140, 141, 142, 143, 144, 145, 158, 159, 160, 161, 162, 177, 178, 198, 219, 98, 99, 100, 240, 241, 115, 116, 117, 118, 119, 120, 121, 122, 125, 126} 

13it [00:24,  3.96it/s]out_max {139, 140, 141, 142, 143, 144, 157, 158, 159, 160, 161, 162, 163, 177, 178, 179, 180, 181, 199, 200, 219, 220, 120, 121, 122, 123, 124} 

14it [00:24,  4.43it/s]out_max {160, 161, 133, 140, 141, 142, 143, 178, 179, 180, 120, 121, 122, 123, 158, 159} 

15it [00:25,  4.81it/s]out_max {140, 141, 142, 143, 144, 145, 146, 157, 158, 159, 161, 162, 163, 164, 176, 177, 179, 180, 181, 183, 197, 198, 199, 200, 201, 74, 202, 203, 88, 89, 90, 219, 20, 221, 218, 222, 104, 106, 107, 240, 241, 120, 121, 122, 123, 124, 125} 

16it [00:25,  5.21it/s]out_max {140, 141, 142, 143, 144, 157, 158, 159, 160, 161, 177, 178, 198, 199, 84, 219, 220, 109, 240, 241, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127} 

17it [00:25,  5.45it/s]out_max {128, 137, 139, 140, 141, 142, 143, 144, 145, 158, 159, 160, 161, 162, 163, 178, 179, 180, 181, 199, 72, 74, 75, 87, 88, 89, 90, 94, 105, 107, 108, 110, 118,120, 121, 122, 123, 124, 125, 126, 127} 

/root/miniconda3/envs/murongmeng/lib/python3.7/site-packages/skimage/_shared/utils.py:394: UserWarning: Color data out of range: Z < 0 in 4 pixels 

  return func(*args, **kwargs) 

推理后的图片

找了一张我认为最好的

编辑

本次体验结束~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值