日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python实现艺术风格绘图

發布時間:2023/12/15 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python实现艺术风格绘图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 簡介
  • 安裝
  • 參數
  • 油筆畫
  • 馬克筆畫
  • 風格遷移
  • 像素風格
  • 遇到的坑
  • 參考文獻

簡介

藝術風格繪圖的論文Stylized Neural Painting及其實現是密歇根大學安娜堡分校、網易伏羲AI實驗室、北京航空航天大學的研究成果。

功能如下:

  • 圖像轉繪畫
    • 油筆畫
    • 馬克筆畫
    • 水彩畫
    • 膠帶藝術
  • 風格遷移
  • 像素風格
  • 高分辨率









安裝

1. 源代碼

2. PyTorch

在PyTorch官網,根據操作系統、Python、CUDA版本后復制執行命令

pip install torch==1.7.0+cu101 torchvision==0.8.1+cu101 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

Python庫

pip install -r requirements.txt

PyTorch模型(按需下載)

  • 油筆畫
  • 馬克筆畫
  • 水彩畫
  • 膠帶藝術

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_L1L1 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

效果




遇到的坑

  • 報錯AttributeError: module 'torch.jit' has no attribute 'unused'
  • pip install torchvision==0.4.1




    參考文獻

  • Stylized Neural Painting
  • stylized-neural-painting GitHub
  • 美術生都要膜拜的AI,照片迅速被畫成藝術畫
  • 根據顯卡型號選擇CUDA和cuDNN進行TensorFlow GPU版本安裝
  • PyTorch踩坑記錄
  • module ‘torch.jit’ has no attribute ‘unused’
  • 總結

    以上是生活随笔為你收集整理的Python实现艺术风格绘图的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。