tensorflow-2.0 技巧 | ImageNet 歸一化


_MEAN_RGB = [123.15, 115.90, 103.06]
def _preprocess_subtract_imagenet_mean(inputs):
    """Subtract Imagenet mean RGB value."""
    mean_rgb = tf.reshape(_MEAN_RGB, [1, 1, 1, 3])
    print("mean_rgb:\n", mean_rgb)
    return inputs - mean_rgb
inputs = tf.random.uniform(shape=[2, 448, 448, 3], maxval=255)
print("inputs:\n", inputs)
imgs_new = _preprocess_subtract_imagenet_mean(inputs)
print("imgs_sub:\n", imgs_new)


會Boardcast!
– 從最后面的維度開始匹配。
– 在前面插入若干維度。
– 將維度的size從1通過expand變到和某個Tensor相同的維度。

總之,Broadcasting操作就是自動實現了若干unsqueeze和expand操作,以使兩個tensor的shape一致,從而完成某些操作(往往是加法)。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM