欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實現(xiàn)一行代碼自動繪制藝術(shù)畫

 更新時間:2022年12月30日 08:58:44   作者:Ckend  
DiscoArt?是一個很牛的開源模塊,它能根據(jù)你給定的關(guān)鍵詞自動繪畫。本文就將利用這一模塊實現(xiàn)一行代碼自動繪制藝術(shù)畫,需要的可以參考一下

DiscoArt 是一個很牛的開源模塊,它能根據(jù)你給定的關(guān)鍵詞自動繪畫。

繪制過程是完全可見的,你可以在 jupyter 頁面上看見這個繪制的過程:

1.準(zhǔn)備

開始之前,你要確保Python和pip已經(jīng)成功安裝在電腦上,如果沒有,可以訪問這篇文章:超詳細Python安裝指南 進行安裝。

(可選1) 如果你用Python的目的是數(shù)據(jù)分析,可以直接安裝Anaconda,它內(nèi)置了Python和pip.

(可選2) 此外,推薦大家用VSCode編輯器,它有許多的優(yōu)點

請選擇以下任一種方式輸入命令安裝依賴

1. Windows 環(huán)境 打開 Cmd (開始-運行-CMD)。

2. MacOS 環(huán)境 打開 Terminal (command+空格輸入Terminal)。

3. 如果你用的是 VSCode編輯器 或 Pycharm,可以直接使用界面下方的Terminal.

pip?install?discoart

為了運行 Discoart, 你需要Python 3.7+ 和支持 CUDA 的 PyTorch.

2.開始使用 Discoart

你可以在Jupyter中運行Discoart,這樣能方便地實時展示繪制過程:

from?discoart?import?create

da = create()

這樣將使用默認的 文本描述 和參數(shù)創(chuàng)建圖像:

text_prompts:
??- A beautiful painting of a singular lighthouse, shining its light across a tumultuous sea of blood by greg rutkowski and thomas kinkade, Trending on artstation.
??- yellow color scheme

init_image:
width_height: [?1280,?768?]

skip_steps:?0
steps:?250

init_scale:?1000
clip_guidance_scale:?5000

tv_scale:?0
range_scale:?150
sat_scale:?0
cutn_batches:?4

diffusion_model:?512x512_diffusion_uncond_finetune_008100
use_secondary_model: True
diffusion_sampling_mode: ddim

perlin_init: False
perlin_mode: mixed
seed:
eta:?0.8
clamp_grad: True
clamp_max:?0.05

randomize_class: True
clip_denoised: False
rand_mag:?0.05

cut_overview:?"[12]*400+[4]*600"
cut_innercut:?"[4]*400+[12]*600"
cut_icgray_p:?"[0.2]*400+[0]*600"
cut_ic_pow:?1.

save_rate:?20
gif_fps:?20
gif_size_ratio:?0.5
n_batches:?4
batch_size:?1
batch_name:
clip_models:
??-?ViT-B-32::openai
??-?ViT-B-16::openai
??-?RN50::openai
clip_models_schedules:

use_vertical_symmetry: False
use_horizontal_symmetry: False
transformation_percent: [0.09]

on_misspelled_token: ignore
diffusion_model_config:
cut_schedules_group:
name_docarray:
skip_event:
stop_event:
text_clip_on_cpu: False
truncate_overlength_prompt: False
image_output: True
visualize_cuts: False
display_rate:?1

創(chuàng)建出來的就是這個圖:

Create 支持的所有參數(shù)如下:

text_prompts:
??- A beautiful painting of a singular lighthouse, shining its light across a tumultuous sea of blood by greg rutkowski and thomas kinkade, Trending on artstation.
??- yellow color scheme

init_image:
width_height: [?1280,?768?]

skip_steps:?0
steps:?250

init_scale:?1000
clip_guidance_scale:?5000

tv_scale:?0
range_scale:?150
sat_scale:?0
cutn_batches:?4

diffusion_model:?512x512_diffusion_uncond_finetune_008100
use_secondary_model: True
diffusion_sampling_mode: ddim

perlin_init: False
perlin_mode: mixed
seed:
eta:?0.8
clamp_grad: True
clamp_max:?0.05

randomize_class: True
clip_denoised: False
rand_mag:?0.05

cut_overview:?"[12]*400+[4]*600"
cut_innercut:?"[4]*400+[12]*600"
cut_icgray_p:?"[0.2]*400+[0]*600"
cut_ic_pow:?1.

save_rate:?20
gif_fps:?20
gif_size_ratio:?0.5
n_batches:?4
batch_size:?1
batch_name:
clip_models:
??-?ViT-B-32::openai
??-?ViT-B-16::openai
??-?RN50::openai
clip_models_schedules:

use_vertical_symmetry: False
use_horizontal_symmetry: False
transformation_percent: [0.09]

on_misspelled_token: ignore
diffusion_model_config:
cut_schedules_group:
name_docarray:
skip_event:
stop_event:
text_clip_on_cpu: False
truncate_overlength_prompt: False
image_output: True
visualize_cuts: False
display_rate:?1

你可以這么使用參數(shù):

from?discoart?import?create

da = create(
????text_prompts='A painting of sea cliffs in a tumultuous storm, Trending on ArtStation.',
????init_image='https://d2vyhzeko0lke5.cloudfront.net/2f4f6dfa5a05e078469ebe57e77b72f0.png',
????skip_steps=100,
)

如果你不是用jupyter運行的,你也可以看到中間結(jié)果,因為最終結(jié)果和中間結(jié)果都會被創(chuàng)建在當(dāng)前工作目錄下,即

./{name-docarray}/{i}-done.png
./{name-docarray}/{i}-step-{j}.png
./{name-docarray}/{i}-progress.png
./{name-docarray}/{i}-progress.gif
./{name-docarray}/da.protobuf.lz4

  • name-docarray是運行時定義的名稱,如果沒有定義,則會隨機生成。
  • i-* 第幾個Batch。
  • *-done-* 是當(dāng)前Batch完成后的最終圖像。
  • *-step-* 是某一步的中間圖像,實時更新。
  • *-progress.png 是到目前為止所有中間結(jié)果的png圖像,實時更新。
  • *-progress.gif 是到目前為止所有中間結(jié)果的動畫 gif,實時更新。
  • da.protobuf.lz4 是到目前為止所有中間結(jié)果的壓縮 protobuf,實時更新。

3.顯示/保存/加載配置

如果你想知道你當(dāng)前繪圖的配置,有三種方法:

from?discoart?import?show_config

show_config(da)?# show the config of the first run
show_config(da[3])?# show the config of the fourth run
show_config(
????'discoart-06030a0198843332edc554ffebfbf288'
)?# show the config of the run with a known DocArray ID

要保存 Document/DocumentArray 的配置:

from?discoart?import?save_config

save_config(da,?'my.yml')?# save the config of the first run
save_config(da[3],?'my.yml')?# save the config of the fourth run

從配置中導(dǎo)入:

from?discoart?import?create, load_config

config = load_config('my.yml')
create(**config)

此外,你還能直接把配置導(dǎo)出為圖像的形式

from?discoart.config?import?save_config_svg

save_config_svg(da)

到此這篇關(guān)于Python實現(xiàn)一行代碼自動繪制藝術(shù)畫的文章就介紹到這了,更多相關(guān)Python繪制藝術(shù)畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解決更新tensorflow后應(yīng)用tensorboard報錯的問題

    解決更新tensorflow后應(yīng)用tensorboard報錯的問題

    這篇文章主要介紹了解決更新tensorflow后應(yīng)用tensorboard報錯的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Python如何建立多個值和單個鍵的映射

    Python如何建立多個值和單個鍵的映射

    在Python中,常見的字典只能映射單個鍵到單個值,若需映射單個鍵到多值,可以通過將值存儲于列表或集合中實現(xiàn),使用列表可以保持元素插入順序,而使用集合則可以去重,collections模塊的defaultdict類簡化了此類多值字典的創(chuàng)建過程
    2024-09-09
  • python實現(xiàn)按關(guān)鍵字篩選日志文件

    python實現(xiàn)按關(guān)鍵字篩選日志文件

    今天小編大家分享一篇python實現(xiàn)按關(guān)鍵字篩選日志文件方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • python+ffmpeg視頻并發(fā)直播壓力測試

    python+ffmpeg視頻并發(fā)直播壓力測試

    這篇文章主要為大家詳細介紹了python+ffmpeg視頻并發(fā)直播壓力測試,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Python中的省略號(Ellipsis)賦值方式詳解

    Python中的省略號(Ellipsis)賦值方式詳解

    在Python編程中,省略號(...)是一種特殊對象,主要用作函數(shù)占位、未實現(xiàn)的方法示例和NumPy數(shù)組處理,本文通過示例詳細解釋了省略號的賦值方式及其在不同編程場景下的應(yīng)用,幫助提升Python編程技巧
    2024-10-10
  • python PyAutoGUI 模擬鼠標(biāo)鍵盤操作和截屏功能

    python PyAutoGUI 模擬鼠標(biāo)鍵盤操作和截屏功能

    一款跨平臺/無依賴的自動化測試工具,目測只能控制鼠標(biāo)/鍵盤/獲取屏幕尺寸/彈出消息框/截屏。這篇文章主要介紹了python PyAutoGUI 模擬鼠標(biāo)鍵盤操作和截屏功能,需要的朋友可以參考下
    2019-08-08
  • 使用Python制作新型冠狀病毒實時疫情圖

    使用Python制作新型冠狀病毒實時疫情圖

    最近被新型冠狀病毒搞的人心惶惶,很多城市被病毒感染,今天小編給大家分享使用Python制作新型冠狀病毒實時疫情圖,感興趣的朋友跟隨小編一起看看吧
    2020-01-01
  • 使用Python的time庫格式化時間的方法

    使用Python的time庫格式化時間的方法

    通過使用Python的time庫,我們可以方便地進行時間處理、格式化、解析和計算等操作,本文介紹了time庫的一些常見功能和使用方法,包括格式化時間、解析時間戳、獲取當(dāng)前時間、計算時間差等,感興趣的朋友一起看看吧
    2023-11-11
  • python網(wǎng)絡(luò)編程之?dāng)?shù)據(jù)傳輸UDP實例分析

    python網(wǎng)絡(luò)編程之?dāng)?shù)據(jù)傳輸UDP實例分析

    這篇文章主要介紹了python網(wǎng)絡(luò)編程之?dāng)?shù)據(jù)傳輸UDP實現(xiàn)方法,實例分析了Python基于UDP協(xié)議的數(shù)據(jù)傳輸實現(xiàn)方法,需要的朋友可以參考下
    2015-05-05
  • Python 中面向接口編程詳情

    Python 中面向接口編程詳情

    這篇文章主要介紹了Python 中面向接口編程詳情,Python 中的接口與大多數(shù)其它語言的處理方式不同,它們的設(shè)計復(fù)雜性也不同,關(guān)于Python 接口編程的介紹,需要的小伙伴可以參考下面文章內(nèi)容
    2022-05-05

最新評論