測試 TPUv2 的 C/P 值

有人用相同演算法實際測試 Google 的 TPUv2 與 NVIDIATesla P100 的 C/P 值了:「Benchmarking Google’s new TPUv2」。

如果以 ResNet-50 當作計算的演算法,可以看到其實 C/P 值的差距沒有想像中大。主要原因是 GPU 可以使用較低的精度計算以加快速度,而非 Google 之前新聞稿故意使用較高精度比較 (TPU 使用 8-bit matrix engine,所以 GPU 使用較低的 fp16 版本比較會比較有參考價值):

真正的差異是在 LSTM

It turns out that the TPU is even faster on the LSTM model (21402 examples/s): ~12.9 times faster than a P100 (1658 examples/s) and ~7.7 times faster than a V100 (2778 examples/s)!

不過這邊就沒特別提到精度了...

Seam Carving (接縫裁剪)

看到有人實做 Seam Carving (接縫裁剪) 了,用 Golang 寫的,放在 GitHubesimov/caire 這邊,副標題「Content aware image resize library」。實做了「Seam Carving for Content-Aware Image Resizing」這篇論文。

Seam Carving 指的是知道內容的 resize,像是把上面這張變成下面這張:

或是變大:

馬上可以想到的應用是需要保留資訊內容,但又想要大量提供資訊的地方,像是 Nuzzle 的縮圖 (或是以前的 Zite),或是網路新聞媒體的首頁所用的縮圖。不知道還有沒有其他地方可以用...

2FA 的 QR code 與 CanvasFingerprintBlock

在「Rasmus Lerdorf 關於 VPS 的介紹測試...」這篇的留言裡,Jimmy 提到 Vultr 是有 2FA 可以用的 (當初沒找到...),於是就花了點時間設定...

但設定的過程中發現 TOTP 的 QR code 出不來,但在 dev console 裡面卻看得到 img 元素。

這種情況前幾個月在另外一個網站上也遇過 (當下拿 Firefox 測也不行),於是就認為他們網站的問題,開了 support ticket 也沒回,一直沒下文的情況下就丟著。現在在 Vultr 上又遇到同樣的問題的話,看起來有可能是我的問題 (或是他們兩個站台都用同樣的 library),於是就仔細點找...

找的過程中間發現有 canvas 元素,然後 canvas 元素有個 inline css 是 display: none;,先試著把這條拿掉,就出現了... 接下來就好猜了。

在 2014 年的「用 Canvas Fingerprint 取代部份 Cookie」這篇就有提過可以用 Canvas 追蹤使用者的問題,於是就有介紹了 CanvasFingerprintBlock 這個在 Google Chrome 上的套件,阻擋 Canvas 的存取。一關掉這個套件就正常了 XDDD

為了隱私問題,套件本身還是掛著,但當遇到發現有 QR code 出不來的時候就知道去 dev console 內改掉 XDDD

然後回到原來本來以為有問題的那個網站,也是一樣進 dev console 改掉後就看得到可以掃了... 看起來這兩個站可能是用一樣的 library?找出來再去戳這兩個站好了...

用 Composer 的 require 限制,擋掉有安全漏洞的 library...

查資料的時候查到的,在 GitHub 上的 Roave/SecurityAdvisories 這個專案利用 Composerrequire 條件限制,擋掉有安全漏洞的 library:

This package ensures that your application doesn't have installed dependencies with known security vulnerabilities.

看一下 composer.json 就知道作法了,裡面的 description 也說明了這個專案的用法:

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

這方法頗不賴的 XDDD

兩個 gperf...

翻資料的時候覺得怎麼跟印象中的不太一樣,多花些時間翻了一下,發現原來有兩個東西同名...

一個是 GNUgperf,給定字串集合,產生 C 或 C++ 的 perfect hash function (i.e. no collision):

GNU gperf is a perfect hash function generator. For a given list of strings, it produces a hash function and hash table, in form of C or C++ code, for looking up a value depending on the input string. The hash function is perfect, which means that the hash table has no collisions, and the hash table lookup needs a single string comparison only.

另外一個是 Google 弄出來的 gperftoolsmalloc() 的替代品以及效能分析工具:

gperftools is a collection of a high-performance multi-threaded malloc() implementation, plus some pretty nifty performance analysis tools.

Twitter 放出來的 Vireo,一套 Open Source 授權的 Video Processing Library

Twitter 放出 Vireo,一套以 MIT License 釋出的 Video Processing Library:「Introducing Vireo: A Lightweight and Versatile Video Processing Library」。專案庫在 GitHubtwitter/vireo 可以取得。

C++ 寫的,另外也已經提供 Scala 的接口,這應該是讓 Twitter 的人可以方便使用:

Vireo is a lightweight and versatile video processing library that powers our video transcoding service, deep learning recognition systems and more. It is written in C++11 and built with functional programming principles. It also optionally comes with Scala wrappers that enable us to build scalable video processing applications within our backend services.

在 Tools 的部份也可以看到很多功能,像是:

thumbnails: extracts keyframes from the input video and saves them as JPG images

viddiff: checks if two video files are functionally identical or not (does not compare data that does not affect the playback behavior)

另外要注意的是,預設不會將 GPL 的套件納入編譯,需要指定 --enable-gpl 才會編進去:

The following libraries are disabled by default. To enable GPL licensed components, they have to be present in your system and --enable-gpl flag have to be explicitly passed to configure

看起來主要就是最常見的那包... (libavformat / libavcodec / libavutil / libswscale / libx264)

Mozilla 實做百度發表的 Speech-To-Text 引擎 Deep Speech

Hacker News 上看到 MozillaGitHub 上的 mozilla/DeepSpeech 這個專案,用 TensorFlow 實做了百度的「Deep Speech: Scaling up end-to-end speech recognition」論文:

A TensorFlow implementation of Baidu's DeepSpeech architecture

語音轉文字的方案,Mozilla 開專案實做出來了...

這程式碼需要安裝 Git Large File Storage 才能完整下載包含訓練資料的部份:

Manually install Git Large File Storage, then clone the repository normally:
git clone https://github.com/mozilla/DeepSpeech

而目前已經有的資料來自於 Mozilla 另外一個專案「Common Voice」:

The Common Voice project is Mozilla's initiative to help teach machines how real people speak.

Common Voice 這個專案目前只有英文,網頁上就可以參與 validation 過程...

curl 將支援 Brotli 壓縮

Twitter 上看到有人提到 curl 支援 Brotli 了:「HTTP: implement Brotli content encoding」。

Brotli 對文字系列的資料比較有幫助 (像是 html):

Unlike most general purpose compression algorithms, Brotli uses a pre-defined 120 kilobyte dictionary, in addition to the dynamically populated ("sliding window") dictionary. The pre-defined dictionary contains over 13000 common words, phrases and other substrings derived from a large corpus of text and HTML documents. Using a pre-defined dictionary has been shown to increase compression where a file mostly contains commonly-used words.

現在還在 master 裡面,之後的 release 版本應該就會支援了...

大型 WordPress 站台會用到的 LudicrousDB (以及 HyperDB)

最近收到 HyperDB 的 mailing list 信件 (開頭是「[HyperDB] How can I set up HyperDB with latest version.」這封),有人提到 HyperDB 很久沒更新了... 結果在信理看到有人回了「stuttter/ludicrousdb」這個專案:

LudicrousDB is an advanced database interface for WordPress that supports replication, failover, load balancing, & partitioning

兩個專案都是抽換掉 WordPress 在處理 database 的 library,然後希望自己控制 master/slave 的讀寫分離以及各機房之間的處理 (還有 replication lag),而不要靠 ProxySQL 這類工具來做 (以時間來看,當初他們發展這些工具時,ProxySQL 這類的方案也還不夠成熟,大家都不會想要選這個方向...)。

先記錄下來,如果之後有遇到時可以當作是一個選項...