Python实现艺术风格绘图
生活随笔
收集整理的這篇文章主要介紹了
Python实现艺术风格绘图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 簡介
- 安裝
- 參數
- 油筆畫
- 馬克筆畫
- 風格遷移
- 像素風格
- 遇到的坑
- 參考文獻
簡介
藝術風格繪圖的論文Stylized Neural Painting及其實現是密歇根大學安娜堡分校、網易伏羲AI實驗室、北京航空航天大學的研究成果。
功能如下:
- 圖像轉繪畫
- 油筆畫
- 馬克筆畫
- 水彩畫
- 膠帶藝術
- 風格遷移
- 像素風格
- 高分辨率
安裝
1. 源代碼
2. PyTorch
在PyTorch官網,根據操作系統、Python、CUDA版本后復制執行命令
Python庫
pip install -r requirements.txtPyTorch模型(按需下載)
- 油筆畫
- 馬克筆畫
- 水彩畫
- 膠帶藝術
PyTorch輕量級模型(GPU顯存不夠下這個)
- 油筆畫
- 馬克筆畫
- 水彩畫
- 膠帶藝術
模型解壓到源碼的目錄中
如果下載速度較慢,可嘗試本人網盤共享的模型下載
參數
| img_path | 測試圖像路徑 | ./test_images/sunflowers.jpg |
| renderer | 渲染器 | oilpaintbrush |
| canvas_color | 畫布顏色 | black |
| canvas_size | 畫布尺寸 | 512 |
| keep_aspect_ratio | 保持輸入長寬比 | False |
| max_m_strokes | 最大沖程數 | 500 |
| max_divide | 圖像最大分割塊數 | 5 |
| m_grid | 劃分一個圖像 | 5 |
| beta_L1 | L1 loss的權重 | 1.0 |
| with_ot_loss | 使用最優轉換loss提高收斂 | False |
| beta_ot | 最優轉換損失的權重 | 0.1 |
| net_G | 網絡類型 | zou-fusion-net-light |
| renderer_checkpoint_dir | 渲染器的路徑 | ./checkpoints_G_oilpaintbrush_light |
| lr | 學習率 | 0.005 |
| output_dir | 輸出圖像路徑 | ./output |
| disable_preview | 是否可視化 | False |
油筆畫
逐步渲染
python demo_prog.py --img_path ./test_images/apple.jpg --canvas_color 'white' --max_m_strokes 500 --max_divide 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --net_G zou-fusion-net逐步渲染(輕量級模型,GPU內存消耗更低,速度更快)
python demo_prog.py --img_path ./test_images/apple.jpg --canvas_color 'white' --max_m_strokes 500 --max_divide 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush_light --net_G zou-fusion-net-light直接使用mxm網絡渲染
python demo.py --img_path ./test_images/apple.jpg --canvas_color 'white' --max_m_strokes 500 --m_grid 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --net_G zou-fusion-net效果
馬克筆畫
逐步渲染
python demo_prog.py --img_path ./test_images/diamond.jpg --canvas_color 'black' --max_m_strokes 500 --max_divide 5 --renderer markerpen --renderer_checkpoint_dir checkpoints_G_markerpen --net_G zou-fusion-net逐步渲染(輕量級模型,GPU內存消耗更低,速度更快)
python demo_prog.py --img_path ./test_images/diamond.jpg --canvas_color 'black' --max_m_strokes 500 --max_divide 5 --renderer markerpen --renderer_checkpoint_dir checkpoints_G_markerpen_light --net_G zou-fusion-net-light直接使用mxm網絡渲染
python demo.py --img_path ./test_images/diamond.jpg --canvas_color 'black' --max_m_strokes 500 --m_grid 5 --renderer markerpen --renderer_checkpoint_dir checkpoints_G_markerpen --net_G zou-fusion-net效果
風格遷移
生成繪畫和筆觸參數
python demo.py --img_path ./test_images/sunflowers.jpg --canvas_color 'white' --max_m_strokes 500 --m_grid 5 --renderer oilpaintbrush --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --net_G zou-fusion-net --output_dir ./output選擇樣式圖像進行風格遷移
python demo_nst.py --renderer oilpaintbrush --vector_file ./output/sunflowers_strokes.npz --style_img_path ./style_images/fire.jpg --content_img_path ./test_images/sunflowers.jpg --canvas_color 'white' --net_G zou-fusion-net --renderer_checkpoint_dir checkpoints_G_oilpaintbrush --transfer_mode 1可指定transfer_mode,0只遷移顏色,1遷移顏色和紋理
效果
像素風格
python demo_8bitart.py --img_path ./test_images/monalisa.jpg --canvas_color 'black' --max_m_strokes 300 --max_divide 4效果
遇到的坑
參考文獻
總結
以上是生活随笔為你收集整理的Python实现艺术风格绘图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信小程序修改switch组件的大小
- 下一篇: Chrome密码导入