無聊看到這個人臉分數專案 自己想說也抓來玩看看 , 折磨了一翻
我用的 python
環境 3.9.18
1 | conda create --name face3 python=3.9 |
1 | git clone https://github.com/ustcqidi/BeautyPredict.git |
安裝以下套件
1 | pip install -r requirements.txt |
requirements.txt
1 | absl-py==2.0.0 |
因為不想下載啥百度 , 所以找到這個資料集 SCUT-FBP5500-Database-Release
下載解壓後建一個資料夾 dataset\SCUT-FBP5500
把東西都往裡面丟
接著建立 dataset\SCUT-FBP5500\All_Ratings
資料夾
1 | md "dataset\SCUT-FBP5500\All_Ratings" |
然後把 All_Ratings.xlsx
裡面的亞洲女人 sheet 另存成 csv 取名為 female_yellow_images.csv
然後用 csvq 篩選想要的即可 , 好像只要前三個欄位
我這裡電腦比較爛就搞個五萬筆
1 | csvq -o female_white_images.csv --write-delimiter ',' 'select Rater,Filename,Rating from `female_yellow_images.csv` limit 50000' |
接著找到 prepare_data.py
只留下亞洲女人的 female_yellow_images.csv
即可
1 | rating_files = ['female_yellow_images.csv'] |
然後 cd 到 train/ldl+resnet
執行 prepare_data.py
標記
1 | cd .\train\ldl+resnet\ |
這個時候會噴 AttributeError: scipy.misc is deprecated and has no attribute toimage
找到這句
1 | img = scipy.misc.toimage(img) |
修改為
1 | img = Image.fromarray(img.astype('uint8'), 'RGB') |
然後會出現 test_lable_distribution.dat
train_lable_distribution.dat
接著執行訓練模型 train_model.py
會噴 ImportError: cannot import name 'Dense' from 'keras.applications.resnet50'
將原本的
1 | from keras.applications.resnet50 import Dense |
改成引用
1 | from tensorflow.python.keras.layers.core import Dense |
這時會噴 ValueError: decay is deprecated in the new Keras optimizer, please check the docstring for valid arguments, or use the legacy optimizer, e.g., tf.keras.optimizers.legacy.SGD.
加入引用
1 | import tensorflow as tf |
然後修改
1 | sgd = SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True) |
變這樣
1 | sgd = tf.keras.optimizers.legacy.SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True) |
然後這裡有個 暴雷
的點要在 train/ldl+resnet
底下建立 model-dropout
這個資料夾 , 不然他的 model 沒辦法放超無言 , 都跑老半天才搞這錯誤
最後會產出 model-ldl-resnet.h5
這個檔案
接著執行 python test_model.py
他會噴 cannot import name 'Dense' from 'keras.applications.resnet50'
修改成以下這樣即可
1 | # from keras.applications.resnet50 import Dense |
最後複製模型 model-ldl-resnet.h5
並切到 inference\ldl+resnet
資料夾底下 , 執行 beauty_predict.py
1 | cd inference\ldl+resnet |
他會喷這個錯 cannot import name 'adam' from 'keras.optimizers'
只要註解以下即可修正
1 | # from keras.optimizers import adam |
然後又會噴一次 cannot import name 'Dense' from 'keras.applications.resnet50'
依照先前的方法修正即可
1 | # from keras.applications.resnet50 import Dense |
最後跑之前把圖片丟到 samples/image
記得修正下你要的檔案名稱 test7
林志玲
1 | beauty_predict(parent_path+"/samples/image",'test7.jpg') |