运行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的权重文件:
下载以后解压到相应目录,就可以输入命令运行了:
python train_frcnn.py -p D:\PythonWorkSpace\VOC2007\VOCdevkit --input_weight_path D:\PythonWorkSpace\Models
其中-p后面是VOC2007的路径,--input_weight_path是VGG权重文件的路径。
运行的画面:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)