在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            博客專欄

            EEPW首頁 > 博客 > 實(shí)踐教程|StableDiffusion圖像生成能力一探!附Int8量化教程與ONNX導(dǎo)出推理

            實(shí)踐教程|StableDiffusion圖像生成能力一探!附Int8量化教程與ONNX導(dǎo)出推理

            發(fā)布人:計(jì)算機(jī)視覺工坊 時(shí)間:2022-09-17 來源:工程師 發(fā)布文章
            作者丨吃飯機(jī)@知乎

            來源丨h(huán)ttps://zhuanlan.zhihu.com/p/200924181編輯丨計(jì)算機(jī)視覺工坊

            導(dǎo)讀

             

            只吃瓜怎么能行,當(dāng)然要上手一試?yán)?!本文送上了一份StableFusion的int8量化教程,以及ONNX導(dǎo)出,甚至是TensorRT加速推理。通過CPU OpenVINO加速也就3分鐘推理。 

            最近stablediffusion大火,但很多人都只是吃瓜,最多也就是在huggingface網(wǎng)站上試一下,這其實(shí)并不夠,作為一個(gè)富有商業(yè)嗅覺的AI從業(yè)者,我****到的更多的是他的商業(yè)能力,不得不說,現(xiàn)在生成類的AI模型,已經(jīng)越來越來接近甚至超越人類水平。

            今天就來一探究竟,看看StableFusion到底能做啥?并附上這個(gè) 超級(jí)大模型的int8量化教程,以及ONNX導(dǎo)出,甚至是TensorRT加速推理。

            請(qǐng)注意,一下的所有測(cè)試案例,都是我用CPU跑出來的,你要問我多慢?通過CPU OpenVINO加速也就3分鐘推理。為什么不用GPU?因?yàn)轱@存不足!

            好在我們用CPU也能比較完善的推理,結(jié)果并不差。未來我們還會(huì)繼續(xù)使用TensorRT推理,加速整個(gè)推理流程。更進(jìn)一步的將StableDiffusion變成生產(chǎn)力工具!

            代碼

            這次我們直接先上代碼,這里面包含了CPU下推理StableDiffusion,以及OpenVINO加速的代碼,同時(shí),也包含了量化腳本,感覺興趣的可以再github提issue。

            git clone https://github.com/luohao123/gaintmodels

            備注:代碼來自大佬,不是本人寫的。不過有問題歡迎提問交流。

            測(cè)試StableDiffusion

            來看看生成的效果,由于模型只能編碼英文,我們就以英文作為promopt。

            A green car with appearance of Tesla Model 3 and Porsche 911

            圖片

            這長(zhǎng)得還真的就像是,保時(shí)捷和model3的合體!中間那個(gè)logo你注意看,感覺并不是特斯拉的logo!有點(diǎn)像保時(shí)捷的logo!~

            A robot Elon Musk in cyberpunk, driving on a Tesla Model X

            圖片

            ModelX倒是有點(diǎn)像,但是馬斯克人呢??

            StableDiffusion這類模型,似乎在生成風(fēng)景畫上表現(xiàn)不錯(cuò)

            A beautiful mansion beside a lake in the woods, with a clean road front of it.

            一棟湖邊的別墅

            圖片

            A beautiful castle beside a waterfall in the woods, detailed, 4k

            瀑布旁邊的城堡

            圖片

            真的是非常的優(yōu)美!而且細(xì)節(jié)清晰可見?。?/p>

            接下來我們測(cè)試一下,一些NSFW的內(nèi)容,請(qǐng)注意,高能預(yù)警,我們的模型把huggingface的SaftyChecker去掉了,為什么?因?yàn)槲覀儾⒉恍枰?!并且這個(gè)模塊是會(huì)占用很多內(nèi)存的!

            A beautiful sexy girl with red hair, 4k, detailed, without any cloth.

            圖片

            由于你懂得原因,我只截取了一部分?。〉?,這個(gè)生成的效果真的令人震驚!過于真實(shí)??!

            再來測(cè)試一些創(chuàng)造性的東西:

            A advanced spaceship with Elon Musk driving on it, detailed, in reality style

            圖片

            這個(gè)非常設(shè)計(jì)的,地區(qū)非常的逼真!看這個(gè)反光,這個(gè)倒影,以及上面的mount,甚至有種自動(dòng)駕駛飛船的感覺。

            A red tv in front of sofa, a child is looking at it with a dog.

            圖片

            在比如這個(gè)圖片,這個(gè)真實(shí)度簡(jiǎn)直超乎了我的預(yù)料,電視機(jī)里面甚至還可以看到倒影!!

            代碼講解

            Experiements on testing GaintModels such as GPT3, StableFusion. We offer TensorRT && Int8 quantization on those gaint models. Make you can inference on a 6GB below GPU mem card!

            Install

            Some requirements to install:

            pip install diffusers
            pip install transformers
            pip install alfred-py

            Models
            1. StableFusion:

            First, we need download stablefusion weights from hugging face.

            git clone https://huggingface.co/CompVis/stable-diffusion-v1-4
            git lfs install
            cd stable-diffusion-v1-4
            git lfs pull

            You should downloading weights using git lfs large file system, the model about 3GB.

            To make unet_2d_condition in stablefusion able to export to onnx, make some modification on diffusers, following: link

            file: diffuers/models/unet_2d_conditions.py

            # L137
            timesteps = timesteps.broadcast_to(sample.shape[0])
            #timesteps = timesteps.broadcast_to(sample.shape[0])
            timesteps = timesteps * torch.ones(sample.shape[0])

            output = {"sample": sample}
            #output = {"sample": sample}

            return output
            return sample

            After that, move stable-diffusion-v1-4 to weights folder. Run:

            python export_df_onnx.py

            To generate onnx models.

            總結(jié)

            生成模型在之前效果其實(shí)并不好,但是到如今,大模型已經(jīng)展示出了驚人的能力。不管是創(chuàng)作還是設(shè)計(jì)logo,從某種方面來說可能甚至是超過常人的。然而大模型都非常大,門檻比較高,我們將StableDiffusion 降維到int8,你甚至只需要一個(gè)CPU就能推理!

            這里面還有無數(shù)種可能等待大家來探索,歡迎關(guān)注、點(diǎn)贊文章,更多教程更新中。


            *博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。

            pic相關(guān)文章:pic是什么




            關(guān)鍵詞: AI

            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉