用 DALL·E 2 的圖當作網誌文章的圖片

Hacker News 上看到「I replaced all our blog thumbnails using DALL·E 2 (deephaven.io)」這個點子,原文在「I replaced all our blog thumbnails using DALL·E 2 for $45: here’s what I learned」這邊。

網誌文章如果包含好的圖片時,曝光度與互動都會比較多。所以作者就想到用 OpenAIDALL·E 2 來搞事了:給個描述,請 DALL·E 2 生成圖片。

文章裡面有很多產生出來的圖都蠻有趣的,像是「a cute blue colored gopher with blue fur programming on multiple monitors displaying many spreadsheets, digital art」這個描述生出來的圖:

不過不算便宜,他花了 US$45 生成大約一百篇文章的圖:

I spent the weekend and $45 in OpenAi credits generating new thumbnails that better represent the content of all 100+ posts from our blog.

如果用先前「玩玩文字轉圖片的 min(DALL·E)」這邊提到的方法自己搞不知道可不可行?

玩玩文字轉圖片的 min(DALL·E)

幾個禮拜前看到「Show HN: I stripped DALL·E Mini to its bare essentials and converted it to Torch (github.com/kuprel)」這個東西,有訓練好的 model 可以直接玩文字轉圖片,GitHub 專案在「min(DALL·E) is a fast, minimal port of DALL·E Mini to PyTorch」這邊可以取得。

因為這是包裝過的版本,裝起來 & 跑起來都很簡單,但沒想到桌機的 1080 Ti 還是跑不動,只能用 CPU 硬扛了,速度上當然是比官網上面列出來用 GPU 的那些慢很多,但至少能跑起來玩看看。

首先是拿官方的句子來玩看看,第一次跑會需要下載 model (會放到我們指定的 pretrained 目錄下):

#!/usr/bin/env python3

from min_dalle import MinDalle
import torch

model = MinDalle(
    models_root='./pretrained',
    dtype=torch.float32,
    device='cpu',
    is_mega=True,
    is_reusable=False,
)

images = model.generate_image(
    text='Nuclear explosion broccoli',
    seed=-1,
    grid_size=2,
    is_seamless=False,
    temperature=1,
    top_k=256,
    supercondition_factor=32,
    is_verbose=False,
)

images = images.save('test.png')

我自己在下載過後,跑每個生成大概都需要十分鐘左右 (參數就像上面列的,CPU 是 AMD 的 5800X,定頻跑在 4.5GHz),出來的結果是這樣:

接著是一些比較普通的描述,這是 sleeping fat cats

然後來測試看看一些比較偏門的詞,像是 Lolicon,這個就差蠻多了:

但感覺有蠻多應用可以掛上去,這樣有點想買張 3090 了...

心情不好時自動送貓貓圖推播的專案

Hacker News 上看到「I wrote a program that sends cats to my phone when I'm sad at the computer (healeycodes.com)」這個東西,居然是用 cam 判斷,當判斷心情不好的時候就推播貓貓的圖片,像是這樣:

除了 machine learning 的部份快,這邊還用到了幾個服務,像是 PushoverThe Cat API (居然有這種服務 XDDD)...

馬上想到前陣子看的 Don't Look Up (千萬別抬頭),裡面好像也有類似的產品 XDDD

Imgur 被 MediaLab 併購

Hacker News 首頁上看到 ImgurMediaLab 併購的消息:「Imgur Acquired by Medialab (imgur.com)」,Imgur 的 PR 稿是在「Celebrating Imgur's Next Chapter」。

看了一下官方的聲明,沒有提到會維持免費或是要收費的事情,另外也沒有提到不會改變之類的事情,我猜應該是會改變商業模式... 之後有遇到再把本來在 blog 上的連結改成 self-hosting。

用 Kroki 搞定 GitLab 上的 UML 圖

在「在自架 GitLab 使用 Kroki 來繪圖」這邊看到 Kroki,先把自己的 GitLab 接上去,整個流程還蠻簡單的...

Kroki uses a simple algorithm (deflate + base64) to encode your diagram in the URL:

GET /plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000

我跟 Heresy 用的方法不太一樣,是透過「Manual Install」這邊的方式裝,只要先把 .jar 檔抓下來放到對應的位置 (我是丟到 /usr/share/kroki/ 這邊),然後自己寫個 systemd 的 service 檔案放到 /lib/systemd/system/kroki.service 裡面:

#
[Unit]
Description=Kroki daemon
After=remote-fs.target

[Service]
ExecStart=/usr/bin/java -jar /usr/share/kroki/kroki-server-v0.13.0.jar
Restart=always
RestartSec=60
Type=simple

[Install]
WantedBy=multi-user.target

預設是 SECURE 模式 (參考「Configuration」這邊的說明),我就不加什麼特別的參數了,另外預設會跑在 port 8000,這邊會需要自己設定 nginx

然後讓 systemd 重讀設定再跑起來:

sudo systemctl daemon-reload
sudo systemctl enable kroki
sudo service kroki restart

目前跑的兩台機器都是 Ubuntu 18.04,內建的 JDK 都是 Java 8 的版本,不確定 Java 11 的環境如何。

Tumblr 對 Yahoo! 流量的影響

也是在 Twitter 上看到的,Yahoo! (Oath) 決定對 Tumblr 上的 NSFW 類圖片下手後對流量的影響:

這張圖應該是出自「Traffic Analysis for port 36:"(36) Yahoo (AS 10310)"」這邊的資料,可以看到頗明顯的下降... 不過九月那個掉下來的部份又是什麼啊 :o

Netflix 的 FrameScope,將效能資料轉成 2D 圖片

Netflix 丟出了 FlameScope,另外一種顯示效能的工具,將效能資料轉成 2D 圖片:「Netflix FlameScope」。

We’re excited to release FlameScope: a new performance visualization tool for analyzing variance, perturbations, single-threaded execution, application startup, and other time-based issues.

然後這個工具同樣是發明火焰圖的 Brendan Gregg 與他的同事 Martin Spier 的作品:

FlameScope was developed by Martin Spier and Brendan Gregg, Netflix cloud performance engineering team. Blog post by Brendan Gregg.

火焰圖 (flame graph) 就是這個:

這次推出的是這樣的圖:

其實是每秒切一次 offset 做出來的圖:

就可以很簡單的看出來哪些區塊以及 pattern 是熱點:

把 git log 用得很開心...?

看到「git log – the Good Parts」這篇文章,裡面研究了 Gitgit log 的各種好用的功能,然後整理出來... (所以是 good parts XD)

作者用的參數是一個一個加上去,所以可以一個階段一個階段了解用途。除了可以用作者推薦的 repository 測試外,我建議大家拿個自己比較熟悉的 open source 專案來測 (有用到比較複雜的架構):

git log
git log --oneline
git log --oneline --decorate
git log --oneline --decorate --all
git log --oneline --decorate --all --graph

看到喜歡的部份可以在 ~/.gitconfig 裡設 alias 使用,像是用 git l 之類的?保留 git log 本身可以避免一些 script 用到這個指令時因為輸出格式跟預期不一樣而爛掉 XD

透過類神經網路,直接把圖變成 HTML

看到 GitHub 上的「emilwallner/Screenshot-to-code-in-Keras」這個專案,直接把圖片轉成 HTML。介紹的文章則是「Turning Design Mockups Into Code With Deep Learning」。

有點像是「將 Sketch 輸出成 iOS/Android 的程式碼」與「透過 NN (類神經網路) 訓練好的系統,直接把圖片轉成程式碼」(後面這篇剛好在介紹文章裡也有提到)。

愈來愈有 NN 在逐步取代人類工作的感覺了...