運行Keras版本的Faster R-CNN(1)


Keras版本的Faster R-CNN源碼下載地址:https://github.com/yhenon/keras-frcnn
下載以后,用PyCharm打開(前提是已經安裝了Tensorflow-gpu和Keras),打開以后可以看到項目的結構:

修改requirements.txt,設置Keras到已安裝的版本,如

Keras==2.0.8

建議版本不要太高,否則會出現錯誤:

TypeError: softmax() got an unexpected keyword argument 'axis'

然后看看需要運行的文件train_frcnn.py的參數相關代碼:

parser.add_option("-p", "--path", dest="train_path", help="Path to training data.")
parser.add_option("-o", "--parser", dest="parser", help="Parser to use. One of simple or pascal_voc",
                default="pascal_voc")
parser.add_option("-n", "--num_rois", type="int", dest="num_rois", help="Number of RoIs to process at once.", default=32)
parser.add_option("--network", dest="network", help="Base network to use. Supports vgg or resnet50.", default='vgg')
parser.add_option("--hf", dest="horizontal_flips", help="Augment with horizontal flips in training. (Default=false).", action="store_true", default=False)
parser.add_option("--vf", dest="vertical_flips", help="Augment with vertical flips in training. (Default=false).", action="store_true", default=False)
parser.add_option("--rot", "--rot_90", dest="rot_90", help="Augment with 90 degree rotations in training. (Default=false).",
                  action="store_true", default=False)
parser.add_option("--num_epochs", type="int", dest="num_epochs", help="Number of epochs.", default=2000)
parser.add_option("--config_filename", dest="config_filename", help=
                "Location to store all the metadata related to the training (to be used when testing).",
                default="config.pickle")
parser.add_option("--output_weight_path", dest="output_weight_path", help="Output path for weights.", default='./model_frcnn.hdf5')
parser.add_option("--input_weight_path", dest="input_weight_path", help="Input path for weights. If not specified, will try to load default weights provided by keras.")

原來的代碼默認的網絡是Resnet50,這里改成了VGG。

VOC2007下載地址:https://pjreddie.com/projects/pascal-voc-dataset-mirror/

下載以后解壓。由於只下載了VOC2007,需要把pascal_voc_parser.py的語句:

data_paths = [os.path.join(input_path,s) for s in ['VOC2007', 'VOC2012']]

中的VOC2012刪掉,否則會報錯。

要運行train_frcnn.py還需要下載Resnet50或者VGG的權重文件:

Resnet50下載地址:https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5

VGG下載地址:https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5

下載以后解壓到相應目錄,就可以輸入命令運行了:

python train_frcnn.py -p D:\PythonWorkSpace\VOC2007\VOCdevkit --input_weight_path D:\PythonWorkSpace\Models

其中-p后面是VOC2007的路徑,--input_weight_path是VGG權重文件的路徑。

運行的畫面:

 


免責聲明!

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



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