影象評估演算法 - NIMA
在視覺業務場景中,對於使用者上傳的影象,經常需要給予一個模糊的評分,用於推薦或者畫像。這就涉及到如何評估影象的好壞。

NIMA
本文介紹一篇,2018年TIP的一篇文章(IEEE Transactions on Image Processing 2018),NIMA: Neural Image Assessment,基於神經網路的影象評估:
- arXiv.org Paper
- GitHub in Keras + Tensorflow
- Google AI Blog: Introducing NIMA: Neural Image Assessment
資料集
資料集:AVA,Aesthetic Visual Analysis,已標註。
標籤如下:
其中:
- 第1維是影象索引;
- 第2維是影象ID;
- 第3-12維是影象評分的分佈,每張圖片約210個人評分,平均1~10分的人數,即The number of votes per image ranges from 78 to 549, with an average of 210 votes;
- 第13-14維是兩個類別,tags,參考tags文件,可能有0~1個類別,用0標記補全;
- 第15維,挑戰賽的ID,25w張圖片,來源於1447個挑戰賽;即We created AVA by collecting approximately 255,000 images covering a wide variety of subjects on 1,447 challenges;
標籤分佈如下:

Distribution
訓練模型
GitHub: neural-image-assessment
訓練,參考train_mobilenet.py
MobileNet的改進:
earth_mover_loss

GAP
EMD (earth mover’s distance) loss,推土機距離,詳解:
import numpy as np import tensorflow as tf from keras import backend as K def main(): arr1 = np.array([[0., 1., 2.], [0., 1., 2.]]) arr2 = np.array([[1., 3., 5.], [2., 4., 6.]]) print(arr1, arr2) sess = tf.Session() cdf_ytrue = K.cumsum(arr1, axis=-1) cdf_ypred = K.cumsum(arr2, axis=-1) v_cdf_ytrue = sess.run(cdf_ytrue) v_cdf_ypred = sess.run(cdf_ypred) print(v_cdf_ytrue, v_cdf_ypred) samplewise_emd = K.sqrt(K.mean(K.square(K.abs(cdf_ytrue - cdf_ypred)), axis=-1)) v_samplewise_emd = sess.run(samplewise_emd) print(v_samplewise_emd) loss = K.mean(samplewise_emd) v_loss = sess.run(loss) print(v_loss) def earth_mover_loss(y_true, y_pred): cdf_ytrue = K.cumsum(y_true, axis=-1) cdf_ypred = K.cumsum(y_pred, axis=-1) samplewise_emd = K.sqrt(K.mean(K.square(K.abs(cdf_ytrue - cdf_ypred)), axis=-1)) return K.mean(samplewise_emd) if __name__ == '__main__': main()
EMD公式:

EMD公式
推理
預測影象:
- 影象預處理;
- 計算期望和方差,期望是得分,方差是歧義度;
改進
- 資料集與真實資料差距較大,資料集偏攝影作品,真實資料為使用者實拍。標註真實資料集,SABC四級分類。
- 增加垃圾資料的得分為0分,如違規圖片,證件等;
- 增加清晰度和顏值等輔助相關;
- AVA資料集打分集中在4-5分,輸出分數區分度不大。
改進:融合其他資料集和美圖資料,使模型輸出區分增大。