機器學習開源框架系列:Torch:3:影像風格遷移

ZZ100861122發表於2020-12-29

這裡寫圖片描述
這篇文章通過一個具體的例子來看一下使用torch可以做的有趣的事情。
事前準備

https://liumiaocn.blog.csdn.net/article/details/109848433

liumiaocn:fast-neural-style liumiao$ th

______ __ | Torch7
/_ / ________/ / | Scientific computing for Lua.
/ / / _ / __/ / _ \ | Type ? for help
/_/ _
// _//// | https://github.com/torch
| http://torch.ch

th>

1
2
3
4
5
6
7
8
9

步驟1: 下載影像風格遷移程式碼

執行 命令:git clone https://github.com/jcjohnson/fast-neural-style

liumiaocn:~ liumiao$ git clone https://github.com/jcjohnson/fast-neural-style
Cloning into ‘fast-neural-style’…
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 256 (delta 0), reused 0 (delta 0), pack-reused 253
Receiving objects: 100% (256/256), 18.65 MiB | 7.14 MiB/s, done.
Resolving deltas: 100% (109/109), done.
liumiaocn:~ liumiao$

1
2
3
4
5
6
7
8
9

步驟2: 下載預先訓練好的模型

liumiaocn:~ liumiao$ cd fast-neural-style/
liumiaocn:fast-neural-style liumiao$ ls
README.md fast_neural_style.lua print_options.lua slow_neural_style.lua webcam_demo.lua
doc images requirements.txt test
fast_neural_style models scripts train.lua
liumiaocn:fast-neural-style liumiao$ sh models/download_style_transfer_models.sh
…省略
liumiaocn:fast-neural-style liumiao$ find models/ -name ‘*.t7’
models//instance_norm/mosaic.t7
models//instance_norm/candy.t7
models//instance_norm/the_scream.t7
models//instance_norm/feathers.t7
models//instance_norm/la_muse.t7
models//instance_norm/udnie.t7
models//eccv16/starry_night.t7
models//eccv16/la_muse.t7
models//eccv16/composition_vii.t7
models//eccv16/the_wave.t7
liumiaocn:fast-neural-style liumiao$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

注意:此步驟中下載指令碼可能會下載失敗,可以通過其他方式比如瀏覽器下載之後移動到相應位置即可。
結果驗證
示例1: 黑貓警長

原始圖片
在這裡插入圖片描述
執行命令:

liumiaocn:fast-neural-style liumiao$ th fast_neural_style.lua \

-model models//eccv16/starry_night.t7
-input_image liumiaocn.jpg
-output_image newstyle-liumiaocn.png
Writing output image to newstyle-liumiaocn.png
liumiaocn:fast-neural-style liumiao$

1
2
3
4
5
6

風格變換之後
在這裡插入圖片描述
注:影像太小,拉伸後很詭異

示例2: 芝加哥

原始圖片
在這裡插入圖片描述
執行命令

liumiaocn:fast-neural-style liumiao$ time -p th fast_neural_style.lua \

-model models//eccv16/starry_night.t7
-input_image city.jpg
-output_image newstyle-city.png
Writing output image to newstyle-city.png
real 7.60
user 9.32
sys 4.79
liumiaocn:fast-neural-style liumiao$

1
2
3
4
5
6
7
8
9

風格變換之後

相關文章