caffe(conversation architecture for faster feature embeding)伯克利视觉和学习中心基于c++/cuda/python实现卷积神经网络框架
    前身decaf,作者贾扬清
    caffe优点
    1)速度快
    2)适合特征提取
    3)开源
    4)一套工具集,实现模型训练,预测,微调等
    5)代码组织良好
    caffe依赖包解析
    1)protobuffer 由谷歌开发实现内存与非易失存储介质交换协议接口
    2)boost c++ 准标准库
    3)GFLAGS在caffe起命令行参数解析的作用
    4)GLOG库谷歌开发记录应用程序日志的实用库
    5)BLAS 基本线性代数子程序
    6)HDF5 高效存储和分发科学数据的新型数据格式
    7)opencv 开源计算机视觉库
    8)LMDB 内存映射型数据库管理器
    9)sanppy 压缩和解压缩的c++库
    caffe实现
    1)数据生成lmdb(提高io利用率)
    2)模型文件
    train.prototxt

    1. name: "ssdJacintoNetV2"
    2. layer {
    3. name: "data"
    4. type: "AnnotatedData"
    5. top: "data"
    6. top: "label"
    7. include {
    8. phase: TRAIN
    9. }
    10. transform_param {
    11. mirror: true
    12. mean_value: 0
    13. mean_value: 0
    14. mean_value: 0
    15. force_color: false
    16. resize_param {
    17. prob: 1
    18. resize_mode: WARP
    19. height: 160 #160
    20. width: 320 #320
    21. interp_mode: LINEAR
    22. interp_mode: AREA
    23. interp_mode: NEAREST
    24. interp_mode: CUBIC
    25. interp_mode: LANCZOS4
    26. }
    27. emit_constraint {
    28. emit_type: CENTER
    29. }
    30. distort_param {
    31. brightness_prob: 0.5
    32. brightness_delta: 32
    33. contrast_prob: 0.5
    34. contrast_lower: 0.5
    35. contrast_upper: 1.5
    36. hue_prob: 0.5
    37. hue_delta: 18
    38. saturation_prob: 0.5
    39. saturation_lower: 0.5
    40. saturation_upper: 1.5
    41. random_order_prob: 0.0
    42. }
    43. expand_param {
    44. prob: 0.5
    45. max_expand_ratio: 4.0
    46. }
    47. }
    48. data_param {
    49. source: "/home/caffe/examples/bsd_ti_5l_320/bsd_left/lmdb/bsd_left_trainval_lmdb"
    50. batch_size: 16
    51. backend: LMDB
    52. }
    53. annotated_data_param {
    54. batch_sampler {
    55. max_sample: 1
    56. max_trials: 1
    57. }
    58. batch_sampler {
    59. sampler {
    60. min_scale: 0.3
    61. max_scale: 1.0
    62. min_aspect_ratio: 0.5
    63. max_aspect_ratio: 2.0
    64. }
    65. sample_constraint {
    66. min_jaccard_overlap: 0.1
    67. }
    68. max_sample: 1
    69. max_trials: 50
    70. }
    71. batch_sampler {
    72. sampler {
    73. min_scale: 0.3
    74. max_scale: 1.0
    75. min_aspect_ratio: 0.5
    76. max_aspect_ratio: 2.0
    77. }
    78. sample_constraint {
    79. min_jaccard_overlap: 0.3
    80. }
    81. max_sample: 1
    82. max_trials: 50
    83. }
    84. batch_sampler {
    85. sampler {
    86. min_scale: 0.3
    87. max_scale: 1.0
    88. min_aspect_ratio: 0.5
    89. max_aspect_ratio: 2.0
    90. }
    91. sample_constraint {
    92. min_jaccard_overlap: 0.5
    93. }
    94. max_sample: 1
    95. max_trials: 50
    96. }
    97. batch_sampler {
    98. sampler {
    99. min_scale: 0.3
    100. max_scale: 1.0
    101. min_aspect_ratio: 0.5
    102. max_aspect_ratio: 2.0
    103. }
    104. sample_constraint {
    105. min_jaccard_overlap: 0.7
    106. }
    107. max_sample: 1
    108. max_trials: 50
    109. }
    110. batch_sampler {
    111. sampler {
    112. min_scale: 0.3
    113. max_scale: 1.0
    114. min_aspect_ratio: 0.5
    115. max_aspect_ratio: 2.0
    116. }
    117. sample_constraint {
    118. min_jaccard_overlap: 0.9
    119. }
    120. max_sample: 1
    121. max_trials: 50
    122. }
    123. batch_sampler {
    124. sampler {
    125. min_scale: 0.3
    126. max_scale: 1.0
    127. min_aspect_ratio: 0.5
    128. max_aspect_ratio: 2.0
    129. }
    130. sample_constraint {
    131. max_jaccard_overlap: 1.0
    132. }
    133. max_sample: 1
    134. max_trials: 50
    135. }
    136. label_map_file: "./labelmap_bsd3class.prototxt"
    137. }
    138. }
    139. layer {
    140. name: "data"
    141. type: "AnnotatedData"
    142. top: "data"
    143. top: "label"
    144. include {
    145. phase: TEST
    146. }
    147. transform_param {
    148. mean_value: 0
    149. mean_value: 0
    150. mean_value: 0
    151. force_color: false
    152. resize_param {
    153. prob: 1
    154. resize_mode: WARP
    155. height: 160 #160
    156. width: 320 #320
    157. interp_mode: LINEAR
    158. }
    159. }
    160. data_param {
    161. source: "/home/caffe/examples/bsd_ti_5l_320/bsd_left/lmdb/bsd_left_test_lmdb"
    162. batch_size: 12
    163. backend: LMDB
    164. }
    165. annotated_data_param {
    166. batch_sampler {
    167. }
    168. label_map_file: "./labelmap_bsd3class.prototxt"
    169. }
    170. }
    171. layer {
    172. name: "data/bias"
    173. type: "Bias"
    174. bottom: "data"
    175. top: "data/bias"
    176. param {
    177. lr_mult: 0
    178. decay_mult: 0
    179. }
    180. bias_param {
    181. filler {
    182. type: "constant"
    183. value: -128
    184. }
    185. }
    186. }
    187. layer {
    188. name: "conv1a"
    189. type: "Convolution"
    190. bottom: "data/bias"
    191. top: "conv1a"
    192. param {
    193. lr_mult: 1
    194. decay_mult: 1
    195. }
    196. param {
    197. lr_mult: 2
    198. decay_mult: 0
    199. }
    200. convolution_param {
    201. num_output: 32
    202. bias_term: true
    203. pad: 2
    204. kernel_size: 5
    205. group: 1
    206. stride: 2
    207. weight_filler {
    208. type: "msra"
    209. }
    210. bias_filler {
    211. type: "constant"
    212. value: 0
    213. }
    214. dilation: 1
    215. }
    216. }
    217. layer {
    218. name: "conv1a/bn"
    219. type: "BatchNorm"
    220. bottom: "conv1a"
    221. top: "conv1a"
    222. batch_norm_param {
    223. moving_average_fraction: 0.99
    224. eps: 0.0001
    225. #scale_bias: true
    226. }
    227. }
    228. layer {
    229. name: "conv1a/relu"
    230. type: "ReLU"
    231. bottom: "conv1a"
    232. top: "conv1a"
    233. }
    234. layer {
    235. name: "conv1b"
    236. type: "Convolution"
    237. bottom: "conv1a"
    238. top: "conv1b"
    239. param {
    240. lr_mult: 1
    241. decay_mult: 1
    242. }
    243. param {
    244. lr_mult: 2
    245. decay_mult: 0
    246. }
    247. convolution_param {
    248. num_output: 32
    249. bias_term: true
    250. pad: 1
    251. kernel_size: 3
    252. group: 4
    253. stride: 1
    254. weight_filler {
    255. type: "msra"
    256. }
    257. bias_filler {
    258. type: "constant"
    259. value: 0
    260. }
    261. dilation: 1
    262. }
    263. }
    264. layer {
    265. name: "conv1b/bn"
    266. type: "BatchNorm"
    267. bottom: "conv1b"
    268. top: "conv1b"
    269. batch_norm_param {
    270. moving_average_fraction: 0.99
    271. eps: 0.0001
    272. #scale_bias: true
    273. }
    274. }
    275. layer {
    276. name: "conv1b/relu"
    277. type: "ReLU"
    278. bottom: "conv1b"
    279. top: "conv1b"
    280. }
    281. layer {
    282. name: "pool1"
    283. type: "Pooling"
    284. bottom: "conv1b"
    285. top: "pool1"
    286. pooling_param {
    287. pool: MAX
    288. kernel_size: 2
    289. stride: 2
    290. }
    291. }
    292. layer {
    293. name: "res2a_branch2a"
    294. type: "Convolution"
    295. bottom: "pool1"
    296. top: "res2a_branch2a"
    297. param {
    298. lr_mult: 1
    299. decay_mult: 1
    300. }
    301. param {
    302. lr_mult: 2
    303. decay_mult: 0
    304. }
    305. convolution_param {
    306. num_output: 64
    307. bias_term: true
    308. pad: 1
    309. kernel_size: 3
    310. group: 1
    311. stride: 1
    312. weight_filler {
    313. type: "msra"
    314. }
    315. bias_filler {
    316. type: "constant"
    317. value: 0
    318. }
    319. dilation: 1
    320. }
    321. }
    322. layer {
    323. name: "res2a_branch2a/bn"
    324. type: "BatchNorm"
    325. bottom: "res2a_branch2a"
    326. top: "res2a_branch2a"
    327. batch_norm_param {
    328. moving_average_fraction: 0.99
    329. eps: 0.0001
    330. #scale_bias: true
    331. }
    332. }
    333. layer {
    334. name: "res2a_branch2a/relu"
    335. type: "ReLU"
    336. bottom: "res2a_branch2a"
    337. top: "res2a_branch2a"
    338. }
    339. layer {
    340. name: "res2a_branch2b"
    341. type: "Convolution"
    342. bottom: "res2a_branch2a"
    343. top: "res2a_branch2b"
    344. param {
    345. lr_mult: 1
    346. decay_mult: 1
    347. }
    348. param {
    349. lr_mult: 2
    350. decay_mult: 0
    351. }
    352. convolution_param {
    353. num_output: 64
    354. bias_term: true
    355. pad: 1
    356. kernel_size: 3
    357. group: 4
    358. stride: 1
    359. weight_filler {
    360. type: "msra"
    361. }
    362. bias_filler {
    363. type: "constant"
    364. value: 0
    365. }
    366. dilation: 1
    367. }
    368. }
    369. layer {
    370. name: "res2a_branch2b/bn"
    371. type: "BatchNorm"
    372. bottom: "res2a_branch2b"
    373. top: "res2a_branch2b"
    374. batch_norm_param {
    375. moving_average_fraction: 0.99
    376. eps: 0.0001
    377. #scale_bias: true
    378. }
    379. }
    380. layer {
    381. name: "res2a_branch2b/relu"
    382. type: "ReLU"
    383. bottom: "res2a_branch2b"
    384. top: "res2a_branch2b"
    385. }
    386. layer {
    387. name: "pool2"
    388. type: "Pooling"
    389. bottom: "res2a_branch2b"
    390. top: "pool2"
    391. pooling_param {
    392. pool: MAX
    393. kernel_size: 2
    394. stride: 2
    395. }
    396. }
    397. layer {
    398. name: "res3a_branch2a"
    399. type: "Convolution"
    400. bottom: "pool2"
    401. top: "res3a_branch2a"
    402. param {
    403. lr_mult: 1
    404. decay_mult: 1
    405. }
    406. param {
    407. lr_mult: 2
    408. decay_mult: 0
    409. }
    410. convolution_param {
    411. num_output: 128
    412. bias_term: true
    413. pad: 1
    414. kernel_size: 3
    415. group: 1
    416. stride: 1
    417. weight_filler {
    418. type: "msra"
    419. }
    420. bias_filler {
    421. type: "constant"
    422. value: 0
    423. }
    424. dilation: 1
    425. }
    426. }
    427. layer {
    428. name: "res3a_branch2a/bn"
    429. type: "BatchNorm"
    430. bottom: "res3a_branch2a"
    431. top: "res3a_branch2a"
    432. batch_norm_param {
    433. moving_average_fraction: 0.99
    434. eps: 0.0001
    435. #scale_bias: true
    436. }
    437. }
    438. layer {
    439. name: "res3a_branch2a/relu"
    440. type: "ReLU"
    441. bottom: "res3a_branch2a"
    442. top: "res3a_branch2a"
    443. }
    444. layer {
    445. name: "res3a_branch2b"
    446. type: "Convolution"
    447. bottom: "res3a_branch2a"
    448. top: "res3a_branch2b"
    449. param {
    450. lr_mult: 1
    451. decay_mult: 1
    452. }
    453. param {
    454. lr_mult: 2
    455. decay_mult: 0
    456. }
    457. convolution_param {
    458. num_output: 128
    459. bias_term: true
    460. pad: 1
    461. kernel_size: 3
    462. group: 4
    463. stride: 1
    464. weight_filler {
    465. type: "msra"
    466. }
    467. bias_filler {
    468. type: "constant"
    469. value: 0
    470. }
    471. dilation: 1
    472. }
    473. }
    474. layer {
    475. name: "res3a_branch2b/bn"
    476. type: "BatchNorm"
    477. bottom: "res3a_branch2b"
    478. top: "res3a_branch2b"
    479. batch_norm_param {
    480. moving_average_fraction: 0.99
    481. eps: 0.0001
    482. #scale_bias: true
    483. }
    484. }
    485. layer {
    486. name: "res3a_branch2b/relu"
    487. type: "ReLU"
    488. bottom: "res3a_branch2b"
    489. top: "res3a_branch2b"
    490. }
    491. layer {
    492. name: "pool3"
    493. type: "Pooling"
    494. bottom: "res3a_branch2b"
    495. top: "pool3"
    496. pooling_param {
    497. pool: MAX
    498. kernel_size: 2
    499. stride: 2
    500. }
    501. }
    502. layer {
    503. name: "res4a_branch2a"
    504. type: "Convolution"
    505. bottom: "pool3"
    506. top: "res4a_branch2a"
    507. param {
    508. lr_mult: 1
    509. decay_mult: 1
    510. }
    511. param {
    512. lr_mult: 2
    513. decay_mult: 0
    514. }
    515. convolution_param {
    516. num_output: 256
    517. bias_term: true
    518. pad: 1
    519. kernel_size: 3
    520. group: 1
    521. stride: 1
    522. weight_filler {
    523. type: "msra"
    524. }
    525. bias_filler {
    526. type: "constant"
    527. value: 0
    528. }
    529. dilation: 1
    530. }
    531. }
    532. layer {
    533. name: "res4a_branch2a/bn"
    534. type: "BatchNorm"
    535. bottom: "res4a_branch2a"
    536. top: "res4a_branch2a"
    537. batch_norm_param {
    538. moving_average_fraction: 0.99
    539. eps: 0.0001
    540. #scale_bias: true
    541. }
    542. }
    543. layer {
    544. name: "res4a_branch2a/relu"
    545. type: "ReLU"
    546. bottom: "res4a_branch2a"
    547. top: "res4a_branch2a"
    548. }
    549. layer {
    550. name: "res4a_branch2b"
    551. type: "Convolution"
    552. bottom: "res4a_branch2a"
    553. top: "res4a_branch2b"
    554. param {
    555. lr_mult: 1
    556. decay_mult: 1
    557. }
    558. param {
    559. lr_mult: 2
    560. decay_mult: 0
    561. }
    562. convolution_param {
    563. num_output: 256
    564. bias_term: true
    565. pad: 1
    566. kernel_size: 3
    567. group: 4
    568. stride: 1
    569. weight_filler {
    570. type: "msra"
    571. }
    572. bias_filler {
    573. type: "constant"
    574. value: 0
    575. }
    576. dilation: 1
    577. }
    578. }
    579. layer {
    580. name: "res4a_branch2b/bn"
    581. type: "BatchNorm"
    582. bottom: "res4a_branch2b"
    583. top: "res4a_branch2b"
    584. batch_norm_param {
    585. moving_average_fraction: 0.99
    586. eps: 0.0001
    587. #scale_bias: true
    588. }
    589. }
    590. layer {
    591. name: "res4a_branch2b/relu"
    592. type: "ReLU"
    593. bottom: "res4a_branch2b"
    594. top: "res4a_branch2b"
    595. }
    596. layer {
    597. name: "pool4"
    598. type: "Pooling"
    599. bottom: "res4a_branch2b"
    600. top: "pool4"
    601. pooling_param {
    602. pool: MAX
    603. kernel_size: 2
    604. stride: 2
    605. }
    606. }
    607. layer {
    608. name: "res5a_branch2a"
    609. type: "Convolution"
    610. bottom: "pool4"
    611. top: "res5a_branch2a"
    612. param {
    613. lr_mult: 1
    614. decay_mult: 1
    615. }
    616. param {
    617. lr_mult: 2
    618. decay_mult: 0
    619. }
    620. convolution_param {
    621. num_output: 512
    622. bias_term: true
    623. pad: 1
    624. kernel_size: 3
    625. group: 1
    626. stride: 1
    627. weight_filler {
    628. type: "msra"
    629. }
    630. bias_filler {
    631. type: "constant"
    632. value: 0
    633. }
    634. dilation: 1
    635. }
    636. }
    637. layer {
    638. name: "res5a_branch2a/bn"
    639. type: "BatchNorm"
    640. bottom: "res5a_branch2a"
    641. top: "res5a_branch2a"
    642. batch_norm_param {
    643. moving_average_fraction: 0.99
    644. eps: 0.0001
    645. #scale_bias: true
    646. }
    647. }
    648. layer {
    649. name: "res5a_branch2a/relu"
    650. type: "ReLU"
    651. bottom: "res5a_branch2a"
    652. top: "res5a_branch2a"
    653. }
    654. layer {
    655. name: "res5a_branch2b"
    656. type: "Convolution"
    657. bottom: "res5a_branch2a"
    658. top: "res5a_branch2b"
    659. param {
    660. lr_mult: 1
    661. decay_mult: 1
    662. }
    663. param {
    664. lr_mult: 2
    665. decay_mult: 0
    666. }
    667. convolution_param {
    668. num_output: 512
    669. bias_term: true
    670. pad: 1
    671. kernel_size: 3
    672. group: 4
    673. stride: 1
    674. weight_filler {
    675. type: "msra"
    676. }
    677. bias_filler {
    678. type: "constant"
    679. value: 0
    680. }
    681. dilation: 1
    682. }
    683. }
    684. layer {
    685. name: "res5a_branch2b/bn"
    686. type: "BatchNorm"
    687. bottom: "res5a_branch2b"
    688. top: "res5a_branch2b"
    689. batch_norm_param {
    690. moving_average_fraction: 0.99
    691. eps: 0.0001
    692. #scale_bias: true
    693. }
    694. }
    695. layer {
    696. name: "res5a_branch2b/relu"
    697. type: "ReLU"
    698. bottom: "res5a_branch2b"
    699. top: "res5a_branch2b"
    700. }
    701. layer {
    702. name: "pool6"
    703. type: "Pooling"
    704. bottom: "res5a_branch2b"
    705. top: "pool6"
    706. pooling_param {
    707. pool: MAX
    708. kernel_size: 2
    709. stride: 2
    710. pad: 0
    711. }
    712. }
    713. layer {
    714. name: "pool7"
    715. type: "Pooling"
    716. bottom: "pool6"
    717. top: "pool7"
    718. pooling_param {
    719. pool: MAX
    720. kernel_size: 2
    721. stride: 2
    722. pad: 0
    723. }
    724. }
    725. layer {
    726. name: "pool8"
    727. type: "Pooling"
    728. bottom: "pool7"
    729. top: "pool8"
    730. pooling_param {
    731. pool: MAX
    732. kernel_size: 2
    733. stride: 2
    734. pad: 0
    735. }
    736. }
    737. layer {
    738. name: "ctx_output1"
    739. type: "Convolution"
    740. bottom: "res4a_branch2b"
    741. top: "ctx_output1"
    742. param {
    743. lr_mult: 1
    744. decay_mult: 1
    745. }
    746. param {
    747. lr_mult: 2
    748. decay_mult: 0
    749. }
    750. convolution_param {
    751. num_output: 256
    752. bias_term: true
    753. pad: 0
    754. kernel_size: 1
    755. group: 1
    756. stride: 1
    757. weight_filler {
    758. type: "msra"
    759. }
    760. bias_filler {
    761. type: "constant"
    762. value: 0
    763. }
    764. dilation: 1
    765. }
    766. }
    767. layer {
    768. name: "ctx_output1/bn"
    769. type: "BatchNorm"
    770. bottom: "ctx_output1"
    771. top: "ctx_output1"
    772. batch_norm_param {
    773. moving_average_fraction: 0.99
    774. eps: 0.0001
    775. #scale_bias: true
    776. }
    777. }
    778. layer {
    779. name: "ctx_output1/relu"
    780. type: "ReLU"
    781. bottom: "ctx_output1"
    782. top: "ctx_output1"
    783. }
    784. layer {
    785. name: "ctx_output2"
    786. type: "Convolution"
    787. bottom: "res5a_branch2b"
    788. top: "ctx_output2"
    789. param {
    790. lr_mult: 1
    791. decay_mult: 1
    792. }
    793. param {
    794. lr_mult: 2
    795. decay_mult: 0
    796. }
    797. convolution_param {
    798. num_output: 256
    799. bias_term: true
    800. pad: 0
    801. kernel_size: 1
    802. group: 1
    803. stride: 1
    804. weight_filler {
    805. type: "msra"
    806. }
    807. bias_filler {
    808. type: "constant"
    809. value: 0
    810. }
    811. dilation: 1
    812. }
    813. }
    814. layer {
    815. name: "ctx_output2/bn"
    816. type: "BatchNorm"
    817. bottom: "ctx_output2"
    818. top: "ctx_output2"
    819. batch_norm_param {
    820. moving_average_fraction: 0.99
    821. eps: 0.0001
    822. #scale_bias: true
    823. }
    824. }
    825. layer {
    826. name: "ctx_output2/relu"
    827. type: "ReLU"
    828. bottom: "ctx_output2"
    829. top: "ctx_output2"
    830. }
    831. layer {
    832. name: "ctx_output3"
    833. type: "Convolution"
    834. bottom: "pool6"
    835. top: "ctx_output3"
    836. param {
    837. lr_mult: 1
    838. decay_mult: 1
    839. }
    840. param {
    841. lr_mult: 2
    842. decay_mult: 0
    843. }
    844. convolution_param {
    845. num_output: 256
    846. bias_term: true
    847. pad: 0
    848. kernel_size: 1
    849. group: 1
    850. stride: 1
    851. weight_filler {
    852. type: "msra"
    853. }
    854. bias_filler {
    855. type: "constant"
    856. value: 0
    857. }
    858. dilation: 1
    859. }
    860. }
    861. layer {
    862. name: "ctx_output3/bn"
    863. type: "BatchNorm"
    864. bottom: "ctx_output3"
    865. top: "ctx_output3"
    866. batch_norm_param {
    867. moving_average_fraction: 0.99
    868. eps: 0.0001
    869. #scale_bias: true
    870. }
    871. }
    872. layer {
    873. name: "ctx_output3/relu"
    874. type: "ReLU"
    875. bottom: "ctx_output3"
    876. top: "ctx_output3"
    877. }
    878. layer {
    879. name: "ctx_output4"
    880. type: "Convolution"
    881. bottom: "pool7"
    882. top: "ctx_output4"
    883. param {
    884. lr_mult: 1
    885. decay_mult: 1
    886. }
    887. param {
    888. lr_mult: 2
    889. decay_mult: 0
    890. }
    891. convolution_param {
    892. num_output: 256
    893. bias_term: true
    894. pad: 0
    895. kernel_size: 1
    896. group: 1
    897. stride: 1
    898. weight_filler {
    899. type: "msra"
    900. }
    901. bias_filler {
    902. type: "constant"
    903. value: 0
    904. }
    905. dilation: 1
    906. }
    907. }
    908. layer {
    909. name: "ctx_output4/bn"
    910. type: "BatchNorm"
    911. bottom: "ctx_output4"
    912. top: "ctx_output4"
    913. batch_norm_param {
    914. moving_average_fraction: 0.99
    915. eps: 0.0001
    916. #scale_bias: true
    917. }
    918. }
    919. layer {
    920. name: "ctx_output4/relu"
    921. type: "ReLU"
    922. bottom: "ctx_output4"
    923. top: "ctx_output4"
    924. }
    925. layer {
    926. name: "ctx_output5"
    927. type: "Convolution"
    928. bottom: "pool8"
    929. top: "ctx_output5"
    930. param {
    931. lr_mult: 1
    932. decay_mult: 1
    933. }
    934. param {
    935. lr_mult: 2
    936. decay_mult: 0
    937. }
    938. convolution_param {
    939. num_output: 256
    940. bias_term: true
    941. pad: 0
    942. kernel_size: 1
    943. group: 1
    944. stride: 1
    945. weight_filler {
    946. type: "msra"
    947. }
    948. bias_filler {
    949. type: "constant"
    950. value: 0
    951. }
    952. dilation: 1
    953. }
    954. }
    955. layer {
    956. name: "ctx_output5/bn"
    957. type: "BatchNorm"
    958. bottom: "ctx_output5"
    959. top: "ctx_output5"
    960. batch_norm_param {
    961. moving_average_fraction: 0.99
    962. eps: 0.0001
    963. #scale_bias: true
    964. }
    965. }
    966. layer {
    967. name: "ctx_output5/relu"
    968. type: "ReLU"
    969. bottom: "ctx_output5"
    970. top: "ctx_output5"
    971. }
    972. layer {
    973. name: "ctx_output1/relu_mbox_loc"
    974. type: "Convolution"
    975. bottom: "ctx_output1"
    976. top: "ctx_output1/relu_mbox_loc"
    977. param {
    978. lr_mult: 1
    979. decay_mult: 1
    980. }
    981. param {
    982. lr_mult: 2
    983. decay_mult: 0
    984. }
    985. convolution_param {
    986. num_output: 16
    987. bias_term: true
    988. pad: 0
    989. kernel_size: 1
    990. group: 1
    991. stride: 1
    992. weight_filler {
    993. type: "msra"
    994. }
    995. bias_filler {
    996. type: "constant"
    997. value: 0
    998. }
    999. dilation: 1
    1000. }
    1001. }
    1002. layer {
    1003. name: "ctx_output1/relu_mbox_loc_perm"
    1004. type: "Permute"
    1005. bottom: "ctx_output1/relu_mbox_loc"
    1006. top: "ctx_output1/relu_mbox_loc_perm"
    1007. permute_param {
    1008. order: 0
    1009. order: 2
    1010. order: 3
    1011. order: 1
    1012. }
    1013. }
    1014. layer {
    1015. name: "ctx_output1/relu_mbox_loc_flat"
    1016. type: "Flatten"
    1017. bottom: "ctx_output1/relu_mbox_loc_perm"
    1018. top: "ctx_output1/relu_mbox_loc_flat"
    1019. flatten_param {
    1020. axis: 1
    1021. }
    1022. }
    1023. layer {
    1024. name: "ctx_output1/relu_mbox_conf"
    1025. type: "Convolution"
    1026. bottom: "ctx_output1"
    1027. top: "ctx_output1/relu_mbox_conf"
    1028. param {
    1029. lr_mult: 1
    1030. decay_mult: 1
    1031. }
    1032. param {
    1033. lr_mult: 2
    1034. decay_mult: 0
    1035. }
    1036. convolution_param {
    1037. num_output: 16#84
    1038. bias_term: true
    1039. pad: 0
    1040. kernel_size: 1
    1041. group: 1
    1042. stride: 1
    1043. weight_filler {
    1044. type: "msra"
    1045. }
    1046. bias_filler {
    1047. type: "constant"
    1048. value: 0
    1049. }
    1050. dilation: 1
    1051. }
    1052. }
    1053. layer {
    1054. name: "ctx_output1/relu_mbox_conf_perm"
    1055. type: "Permute"
    1056. bottom: "ctx_output1/relu_mbox_conf"
    1057. top: "ctx_output1/relu_mbox_conf_perm"
    1058. permute_param {
    1059. order: 0
    1060. order: 2
    1061. order: 3
    1062. order: 1
    1063. }
    1064. }
    1065. layer {
    1066. name: "ctx_output1/relu_mbox_conf_flat"
    1067. type: "Flatten"
    1068. bottom: "ctx_output1/relu_mbox_conf_perm"
    1069. top: "ctx_output1/relu_mbox_conf_flat"
    1070. flatten_param {
    1071. axis: 1
    1072. }
    1073. }
    1074. layer {
    1075. name: "ctx_output1/relu_mbox_priorbox"
    1076. type: "PriorBox"
    1077. bottom: "ctx_output1"
    1078. bottom: "data"
    1079. top: "ctx_output1/relu_mbox_priorbox"
    1080. prior_box_param {
    1081. min_size: 24 #14.72
    1082. max_size: 50.24 #36.8
    1083. aspect_ratio: 2
    1084. flip: true
    1085. clip: false
    1086. variance: 0.1
    1087. variance: 0.1
    1088. variance: 0.2
    1089. variance: 0.2
    1090. offset: 0.5
    1091. }
    1092. }
    1093. layer {
    1094. name: "ctx_output2/relu_mbox_loc"
    1095. type: "Convolution"
    1096. bottom: "ctx_output2"
    1097. top: "ctx_output2/relu_mbox_loc"
    1098. param {
    1099. lr_mult: 1
    1100. decay_mult: 1
    1101. }
    1102. param {
    1103. lr_mult: 2
    1104. decay_mult: 0
    1105. }
    1106. convolution_param {
    1107. num_output: 24
    1108. bias_term: true
    1109. pad: 0
    1110. kernel_size: 1
    1111. group: 1
    1112. stride: 1
    1113. weight_filler {
    1114. type: "msra"
    1115. }
    1116. bias_filler {
    1117. type: "constant"
    1118. value: 0
    1119. }
    1120. dilation: 1
    1121. }
    1122. }
    1123. layer {
    1124. name: "ctx_output2/relu_mbox_loc_perm"
    1125. type: "Permute"
    1126. bottom: "ctx_output2/relu_mbox_loc"
    1127. top: "ctx_output2/relu_mbox_loc_perm"
    1128. permute_param {
    1129. order: 0
    1130. order: 2
    1131. order: 3
    1132. order: 1
    1133. }
    1134. }
    1135. layer {
    1136. name: "ctx_output2/relu_mbox_loc_flat"
    1137. type: "Flatten"
    1138. bottom: "ctx_output2/relu_mbox_loc_perm"
    1139. top: "ctx_output2/relu_mbox_loc_flat"
    1140. flatten_param {
    1141. axis: 1
    1142. }
    1143. }
    1144. layer {
    1145. name: "ctx_output2/relu_mbox_conf"
    1146. type: "Convolution"
    1147. bottom: "ctx_output2"
    1148. top: "ctx_output2/relu_mbox_conf"
    1149. param {
    1150. lr_mult: 1
    1151. decay_mult: 1
    1152. }
    1153. param {
    1154. lr_mult: 2
    1155. decay_mult: 0
    1156. }
    1157. convolution_param {
    1158. num_output: 24#126
    1159. bias_term: true
    1160. pad: 0
    1161. kernel_size: 1
    1162. group: 1
    1163. stride: 1
    1164. weight_filler {
    1165. type: "msra"
    1166. }
    1167. bias_filler {
    1168. type: "constant"
    1169. value: 0
    1170. }
    1171. dilation: 1
    1172. }
    1173. }
    1174. layer {
    1175. name: "ctx_output2/relu_mbox_conf_perm"
    1176. type: "Permute"
    1177. bottom: "ctx_output2/relu_mbox_conf"
    1178. top: "ctx_output2/relu_mbox_conf_perm"
    1179. permute_param {
    1180. order: 0
    1181. order: 2
    1182. order: 3
    1183. order: 1
    1184. }
    1185. }
    1186. layer {
    1187. name: "ctx_output2/relu_mbox_conf_flat"
    1188. type: "Flatten"
    1189. bottom: "ctx_output2/relu_mbox_conf_perm"
    1190. top: "ctx_output2/relu_mbox_conf_flat"
    1191. flatten_param {
    1192. axis: 1
    1193. }
    1194. }
    1195. layer {
    1196. name: "ctx_output2/relu_mbox_priorbox"
    1197. type: "PriorBox"
    1198. bottom: "ctx_output2"
    1199. bottom: "data"
    1200. top: "ctx_output2/relu_mbox_priorbox"
    1201. prior_box_param {
    1202. min_size: 50.24 #36.8
    1203. max_size: 76.48 #110.4
    1204. aspect_ratio: 2
    1205. aspect_ratio: 3
    1206. flip: true
    1207. clip: false
    1208. variance: 0.1
    1209. variance: 0.1
    1210. variance: 0.2
    1211. variance: 0.2
    1212. offset: 0.5
    1213. }
    1214. }
    1215. layer {
    1216. name: "ctx_output3/relu_mbox_loc"
    1217. type: "Convolution"
    1218. bottom: "ctx_output3"
    1219. top: "ctx_output3/relu_mbox_loc"
    1220. param {
    1221. lr_mult: 1
    1222. decay_mult: 1
    1223. }
    1224. param {
    1225. lr_mult: 2
    1226. decay_mult: 0
    1227. }
    1228. convolution_param {
    1229. num_output: 24
    1230. bias_term: true
    1231. pad: 0
    1232. kernel_size: 1
    1233. group: 1
    1234. stride: 1
    1235. weight_filler {
    1236. type: "msra"
    1237. }
    1238. bias_filler {
    1239. type: "constant"
    1240. value: 0
    1241. }
    1242. dilation: 1
    1243. }
    1244. }
    1245. layer {
    1246. name: "ctx_output3/relu_mbox_loc_perm"
    1247. type: "Permute"
    1248. bottom: "ctx_output3/relu_mbox_loc"
    1249. top: "ctx_output3/relu_mbox_loc_perm"
    1250. permute_param {
    1251. order: 0
    1252. order: 2
    1253. order: 3
    1254. order: 1
    1255. }
    1256. }
    1257. layer {
    1258. name: "ctx_output3/relu_mbox_loc_flat"
    1259. type: "Flatten"
    1260. bottom: "ctx_output3/relu_mbox_loc_perm"
    1261. top: "ctx_output3/relu_mbox_loc_flat"
    1262. flatten_param {
    1263. axis: 1
    1264. }
    1265. }
    1266. layer {
    1267. name: "ctx_output3/relu_mbox_conf"
    1268. type: "Convolution"
    1269. bottom: "ctx_output3"
    1270. top: "ctx_output3/relu_mbox_conf"
    1271. param {
    1272. lr_mult: 1
    1273. decay_mult: 1
    1274. }
    1275. param {
    1276. lr_mult: 2
    1277. decay_mult: 0
    1278. }
    1279. convolution_param {
    1280. num_output: 24#126
    1281. bias_term: true
    1282. pad: 0
    1283. kernel_size: 1
    1284. group: 1
    1285. stride: 1
    1286. weight_filler {
    1287. type: "msra"
    1288. }
    1289. bias_filler {
    1290. type: "constant"
    1291. value: 0
    1292. }
    1293. dilation: 1
    1294. }
    1295. }
    1296. layer {
    1297. name: "ctx_output3/relu_mbox_conf_perm"
    1298. type: "Permute"
    1299. bottom: "ctx_output3/relu_mbox_conf"
    1300. top: "ctx_output3/relu_mbox_conf_perm"
    1301. permute_param {
    1302. order: 0
    1303. order: 2
    1304. order: 3
    1305. order: 1
    1306. }
    1307. }
    1308. layer {
    1309. name: "ctx_output3/relu_mbox_conf_flat"
    1310. type: "Flatten"
    1311. bottom: "ctx_output3/relu_mbox_conf_perm"
    1312. top: "ctx_output3/relu_mbox_conf_flat"
    1313. flatten_param {
    1314. axis: 1
    1315. }
    1316. }
    1317. layer {
    1318. name: "ctx_output3/relu_mbox_priorbox"
    1319. type: "PriorBox"
    1320. bottom: "ctx_output3"
    1321. bottom: "data"
    1322. top: "ctx_output3/relu_mbox_priorbox"
    1323. prior_box_param {
    1324. min_size: 76.48 #110.4
    1325. max_size: 102.72 #184.0
    1326. aspect_ratio: 2
    1327. aspect_ratio: 3
    1328. flip: true
    1329. clip: false
    1330. variance: 0.1
    1331. variance: 0.1
    1332. variance: 0.2
    1333. variance: 0.2
    1334. offset: 0.5
    1335. }
    1336. }
    1337. layer {
    1338. name: "ctx_output4/relu_mbox_loc"
    1339. type: "Convolution"
    1340. bottom: "ctx_output4"
    1341. top: "ctx_output4/relu_mbox_loc"
    1342. param {
    1343. lr_mult: 1
    1344. decay_mult: 1
    1345. }
    1346. param {
    1347. lr_mult: 2
    1348. decay_mult: 0
    1349. }
    1350. convolution_param {
    1351. num_output: 24
    1352. bias_term: true
    1353. pad: 0
    1354. kernel_size: 1
    1355. group: 1
    1356. stride: 1
    1357. weight_filler {
    1358. type: "msra"
    1359. }
    1360. bias_filler {
    1361. type: "constant"
    1362. value: 0
    1363. }
    1364. dilation: 1
    1365. }
    1366. }
    1367. layer {
    1368. name: "ctx_output4/relu_mbox_loc_perm"
    1369. type: "Permute"
    1370. bottom: "ctx_output4/relu_mbox_loc"
    1371. top: "ctx_output4/relu_mbox_loc_perm"
    1372. permute_param {
    1373. order: 0
    1374. order: 2
    1375. order: 3
    1376. order: 1
    1377. }
    1378. }
    1379. layer {
    1380. name: "ctx_output4/relu_mbox_loc_flat"
    1381. type: "Flatten"
    1382. bottom: "ctx_output4/relu_mbox_loc_perm"
    1383. top: "ctx_output4/relu_mbox_loc_flat"
    1384. flatten_param {
    1385. axis: 1
    1386. }
    1387. }
    1388. layer {
    1389. name: "ctx_output4/relu_mbox_conf"
    1390. type: "Convolution"
    1391. bottom: "ctx_output4"
    1392. top: "ctx_output4/relu_mbox_conf"
    1393. param {
    1394. lr_mult: 1
    1395. decay_mult: 1
    1396. }
    1397. param {
    1398. lr_mult: 2
    1399. decay_mult: 0
    1400. }
    1401. convolution_param {
    1402. num_output: 24#126
    1403. bias_term: true
    1404. pad: 0
    1405. kernel_size: 1
    1406. group: 1
    1407. stride: 1
    1408. weight_filler {
    1409. type: "msra"
    1410. }
    1411. bias_filler {
    1412. type: "constant"
    1413. value: 0
    1414. }
    1415. dilation: 1
    1416. }
    1417. }
    1418. layer {
    1419. name: "ctx_output4/relu_mbox_conf_perm"
    1420. type: "Permute"
    1421. bottom: "ctx_output4/relu_mbox_conf"
    1422. top: "ctx_output4/relu_mbox_conf_perm"
    1423. permute_param {
    1424. order: 0
    1425. order: 2
    1426. order: 3
    1427. order: 1
    1428. }
    1429. }
    1430. layer {
    1431. name: "ctx_output4/relu_mbox_conf_flat"
    1432. type: "Flatten"
    1433. bottom: "ctx_output4/relu_mbox_conf_perm"
    1434. top: "ctx_output4/relu_mbox_conf_flat"
    1435. flatten_param {
    1436. axis: 1
    1437. }
    1438. }
    1439. layer {
    1440. name: "ctx_output4/relu_mbox_priorbox"
    1441. type: "PriorBox"
    1442. bottom: "ctx_output4"
    1443. bottom: "data"
    1444. top: "ctx_output4/relu_mbox_priorbox"
    1445. prior_box_param {
    1446. min_size: 102.72 #184.0
    1447. max_size: 128.96 #257.6
    1448. aspect_ratio: 2
    1449. aspect_ratio: 3
    1450. flip: true
    1451. clip: false
    1452. variance: 0.1
    1453. variance: 0.1
    1454. variance: 0.2
    1455. variance: 0.2
    1456. offset: 0.5
    1457. }
    1458. }
    1459. layer {
    1460. name: "ctx_output5/relu_mbox_loc"
    1461. type: "Convolution"
    1462. bottom: "ctx_output5"
    1463. top: "ctx_output5/relu_mbox_loc"
    1464. param {
    1465. lr_mult: 1
    1466. decay_mult: 1
    1467. }
    1468. param {
    1469. lr_mult: 2
    1470. decay_mult: 0
    1471. }
    1472. convolution_param {
    1473. num_output: 16
    1474. bias_term: true
    1475. pad: 0
    1476. kernel_size: 1
    1477. group: 1
    1478. stride: 1
    1479. weight_filler {
    1480. type: "msra"
    1481. }
    1482. bias_filler {
    1483. type: "constant"
    1484. value: 0
    1485. }
    1486. dilation: 1
    1487. }
    1488. }
    1489. layer {
    1490. name: "ctx_output5/relu_mbox_loc_perm"
    1491. type: "Permute"
    1492. bottom: "ctx_output5/relu_mbox_loc"
    1493. top: "ctx_output5/relu_mbox_loc_perm"
    1494. permute_param {
    1495. order: 0
    1496. order: 2
    1497. order: 3
    1498. order: 1
    1499. }
    1500. }
    1501. layer {
    1502. name: "ctx_output5/relu_mbox_loc_flat"
    1503. type: "Flatten"
    1504. bottom: "ctx_output5/relu_mbox_loc_perm"
    1505. top: "ctx_output5/relu_mbox_loc_flat"
    1506. flatten_param {
    1507. axis: 1
    1508. }
    1509. }
    1510. layer {
    1511. name: "ctx_output5/relu_mbox_conf"
    1512. type: "Convolution"
    1513. bottom: "ctx_output5"
    1514. top: "ctx_output5/relu_mbox_conf"
    1515. param {
    1516. lr_mult: 1
    1517. decay_mult: 1
    1518. }
    1519. param {
    1520. lr_mult: 2
    1521. decay_mult: 0
    1522. }
    1523. convolution_param {
    1524. num_output: 16#84
    1525. bias_term: true
    1526. pad: 0
    1527. kernel_size: 1
    1528. group: 1
    1529. stride: 1
    1530. weight_filler {
    1531. type: "msra"
    1532. }
    1533. bias_filler {
    1534. type: "constant"
    1535. value: 0
    1536. }
    1537. dilation: 1
    1538. }
    1539. }
    1540. layer {
    1541. name: "ctx_output5/relu_mbox_conf_perm"
    1542. type: "Permute"
    1543. bottom: "ctx_output5/relu_mbox_conf"
    1544. top: "ctx_output5/relu_mbox_conf_perm"
    1545. permute_param {
    1546. order: 0
    1547. order: 2
    1548. order: 3
    1549. order: 1
    1550. }
    1551. }
    1552. layer {
    1553. name: "ctx_output5/relu_mbox_conf_flat"
    1554. type: "Flatten"
    1555. bottom: "ctx_output5/relu_mbox_conf_perm"
    1556. top: "ctx_output5/relu_mbox_conf_flat"
    1557. flatten_param {
    1558. axis: 1
    1559. }
    1560. }
    1561. layer {
    1562. name: "ctx_output5/relu_mbox_priorbox"
    1563. type: "PriorBox"
    1564. bottom: "ctx_output5"
    1565. bottom: "data"
    1566. top: "ctx_output5/relu_mbox_priorbox"
    1567. prior_box_param {
    1568. min_size: 128.96 #257.6
    1569. max_size: 160 #331.2
    1570. aspect_ratio: 2
    1571. flip: true
    1572. clip: false
    1573. variance: 0.1
    1574. variance: 0.1
    1575. variance: 0.2
    1576. variance: 0.2
    1577. offset: 0.5
    1578. }
    1579. }
    1580. layer {
    1581. name: "mbox_loc"
    1582. type: "Concat"
    1583. bottom: "ctx_output1/relu_mbox_loc_flat"
    1584. bottom: "ctx_output2/relu_mbox_loc_flat"
    1585. bottom: "ctx_output3/relu_mbox_loc_flat"
    1586. bottom: "ctx_output4/relu_mbox_loc_flat"
    1587. bottom: "ctx_output5/relu_mbox_loc_flat"
    1588. top: "mbox_loc"
    1589. concat_param {
    1590. axis: 1
    1591. }
    1592. }
    1593. layer {
    1594. name: "mbox_conf"
    1595. type: "Concat"
    1596. bottom: "ctx_output1/relu_mbox_conf_flat"
    1597. bottom: "ctx_output2/relu_mbox_conf_flat"
    1598. bottom: "ctx_output3/relu_mbox_conf_flat"
    1599. bottom: "ctx_output4/relu_mbox_conf_flat"
    1600. bottom: "ctx_output5/relu_mbox_conf_flat"
    1601. top: "mbox_conf"
    1602. concat_param {
    1603. axis: 1
    1604. }
    1605. }
    1606. layer {
    1607. name: "mbox_priorbox"
    1608. type: "Concat"
    1609. bottom: "ctx_output1/relu_mbox_priorbox"
    1610. bottom: "ctx_output2/relu_mbox_priorbox"
    1611. bottom: "ctx_output3/relu_mbox_priorbox"
    1612. bottom: "ctx_output4/relu_mbox_priorbox"
    1613. bottom: "ctx_output5/relu_mbox_priorbox"
    1614. top: "mbox_priorbox"
    1615. concat_param {
    1616. axis: 2
    1617. }
    1618. }
    1619. layer {
    1620. name: "mbox_loss"
    1621. type: "MultiBoxLoss"
    1622. bottom: "mbox_loc"
    1623. bottom: "mbox_conf"
    1624. bottom: "mbox_priorbox"
    1625. bottom: "label"
    1626. top: "mbox_loss"
    1627. include {
    1628. phase: TRAIN
    1629. }
    1630. propagate_down: true
    1631. propagate_down: true
    1632. propagate_down: false
    1633. propagate_down: false
    1634. loss_param {
    1635. normalization: VALID
    1636. }
    1637. multibox_loss_param {
    1638. loc_loss_type: SMOOTH_L1
    1639. conf_loss_type: SOFTMAX
    1640. loc_weight: 1.0
    1641. num_classes: 4
    1642. share_location: true
    1643. match_type: PER_PREDICTION
    1644. overlap_threshold: 0.5
    1645. use_prior_for_matching: true
    1646. background_label_id: 0
    1647. use_difficult_gt: true
    1648. neg_pos_ratio: 3.0
    1649. neg_overlap: 0.5
    1650. code_type: CENTER_SIZE
    1651. ignore_cross_boundary_bbox: false
    1652. mining_type: MAX_NEGATIVE
    1653. }
    1654. }
    1655. layer {
    1656. name: "mbox_conf_reshape"
    1657. type: "Reshape"
    1658. bottom: "mbox_conf"
    1659. top: "mbox_conf_reshape"
    1660. reshape_param {
    1661. shape {
    1662. dim: 0
    1663. dim: -1
    1664. dim: 4
    1665. }
    1666. }
    1667. }
    1668. layer {
    1669. name: "mbox_conf_softmax"
    1670. type: "Softmax"
    1671. bottom: "mbox_conf_reshape"
    1672. top: "mbox_conf_softmax"
    1673. softmax_param {
    1674. axis: 2
    1675. }
    1676. }
    1677. layer {
    1678. name: "mbox_conf_flatten"
    1679. type: "Flatten"
    1680. bottom: "mbox_conf_softmax"
    1681. top: "mbox_conf_flatten"
    1682. flatten_param {
    1683. axis: 1
    1684. }
    1685. }
    1686. layer {
    1687. name: "detection_out"
    1688. type: "DetectionOutput"
    1689. bottom: "mbox_loc"
    1690. bottom: "mbox_conf_flatten"
    1691. bottom: "mbox_priorbox"
    1692. top: "detection_out"
    1693. include {
    1694. phase: TEST
    1695. }
    1696. detection_output_param {
    1697. num_classes: 4
    1698. share_location: true
    1699. background_label_id: 0
    1700. nms_param {
    1701. nms_threshold: 0.45
    1702. top_k: 400
    1703. }
    1704. code_type: CENTER_SIZE
    1705. keep_top_k: 200
    1706. confidence_threshold: 0.01
    1707. }
    1708. }
    1709. layer {
    1710. name: "detection_eval"
    1711. type: "DetectionEvaluate"
    1712. bottom: "detection_out"
    1713. bottom: "label"
    1714. top: "detection_eval"
    1715. include {
    1716. phase: TEST
    1717. }
    1718. detection_evaluate_param {
    1719. num_classes: 4
    1720. background_label_id: 0
    1721. overlap_threshold: 0.5
    1722. evaluate_difficult_gt: false
    1723. #name_size_file: "/home/caffe/examples/bsd_ti_5l_320/bsd_r_mini/VOC2007/test_name_size.txt"
    1724. }
    1725. }

    3) 训练超参数

    net: "ti_bsd_5little_200_400_4pr.prototxt" ##########
    test_iter: 10 ##########
    test_interval: 100 ##########
    base_lr: 0.01 #0.0005
    display: 100
    max_iter: 100000 ##########
    lr_policy: "multistep"
    gamma: 0.1
    power: 1.0
    momentum: 0.9
    weight_decay: 0.0001
    snapshot: 10000
    snapshot_prefix: "snapshot/4pr" ###########
    solver_mode: GPU
    debug_info: false
    snapshot_after_train: true
    test_initialization: false
    average_loss: 10
    stepvalue: 60000
    stepvalue: 90000
    stepvalue: 300000
    iter_size: 2
    type: "SGD"
    eval_type: "detection"
    ap_version: "11point"
    show_per_class_result: true
    

    4)模型训练
    sh train.sh

    #!/bin/sh
    ../../build/tools/caffe train -solver="solver_train.prototxt" -gpu=0 -snapshot="./snapshot/4pr_iter_100000.solverstate" -gpu=0  
    2>&1 | tee ./bsd.log
    

    5)模型预测 ./build/tools/caffe.bin test -model ./test.prototxt -weights ./lenet_iter_1000.caffemodel -iterations 100 (bachsize*iter=number of test images)
    deploy文件

    name: "ssdJacintoNetV2"
    input: "data"
    input_shape{
          dim=1
          dim=3
          dim: 160 #160
          dim: 320  #320
        }
    
    layer {
      name: "data/bias"
      type: "Bias"
      bottom: "data"
      top: "data/bias"
      param {
        lr_mult: 0
        decay_mult: 0
      }
      bias_param {
        filler {
          type: "constant"
          value: -128
        }
      }
    }
    
    layer {
      name: "conv1a"
      type: "Convolution"
      bottom: "data/bias"
      top: "conv1a"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 32
        bias_term: true
        pad: 2
        kernel_size: 5
        group: 1
        stride: 2
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "conv1a/bn"
      type: "BatchNorm"
      bottom: "conv1a"
      top: "conv1a"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "conv1a/relu"
      type: "ReLU"
      bottom: "conv1a"
      top: "conv1a"
    }
    layer {
      name: "conv1b"
      type: "Convolution"
      bottom: "conv1a"
      top: "conv1b"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 32
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 4
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "conv1b/bn"
      type: "BatchNorm"
      bottom: "conv1b"
      top: "conv1b"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "conv1b/relu"
      type: "ReLU"
      bottom: "conv1b"
      top: "conv1b"
    }
    layer {
      name: "pool1"
      type: "Pooling"
      bottom: "conv1b"
      top: "pool1"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
      }
    }
    layer {
      name: "res2a_branch2a"
      type: "Convolution"
      bottom: "pool1"
      top: "res2a_branch2a"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 64
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res2a_branch2a/bn"
      type: "BatchNorm"
      bottom: "res2a_branch2a"
      top: "res2a_branch2a"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res2a_branch2a/relu"
      type: "ReLU"
      bottom: "res2a_branch2a"
      top: "res2a_branch2a"
    }
    layer {
      name: "res2a_branch2b"
      type: "Convolution"
      bottom: "res2a_branch2a"
      top: "res2a_branch2b"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 64
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 4
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res2a_branch2b/bn"
      type: "BatchNorm"
      bottom: "res2a_branch2b"
      top: "res2a_branch2b"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res2a_branch2b/relu"
      type: "ReLU"
      bottom: "res2a_branch2b"
      top: "res2a_branch2b"
    }
    layer {
      name: "pool2"
      type: "Pooling"
      bottom: "res2a_branch2b"
      top: "pool2"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
      }
    }
    layer {
      name: "res3a_branch2a"
      type: "Convolution"
      bottom: "pool2"
      top: "res3a_branch2a"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 128
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res3a_branch2a/bn"
      type: "BatchNorm"
      bottom: "res3a_branch2a"
      top: "res3a_branch2a"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res3a_branch2a/relu"
      type: "ReLU"
      bottom: "res3a_branch2a"
      top: "res3a_branch2a"
    }
    layer {
      name: "res3a_branch2b"
      type: "Convolution"
      bottom: "res3a_branch2a"
      top: "res3a_branch2b"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 128
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 4
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res3a_branch2b/bn"
      type: "BatchNorm"
      bottom: "res3a_branch2b"
      top: "res3a_branch2b"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res3a_branch2b/relu"
      type: "ReLU"
      bottom: "res3a_branch2b"
      top: "res3a_branch2b"
    }
    layer {
      name: "pool3"
      type: "Pooling"
      bottom: "res3a_branch2b"
      top: "pool3"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
      }
    }
    layer {
      name: "res4a_branch2a"
      type: "Convolution"
      bottom: "pool3"
      top: "res4a_branch2a"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res4a_branch2a/bn"
      type: "BatchNorm"
      bottom: "res4a_branch2a"
      top: "res4a_branch2a"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res4a_branch2a/relu"
      type: "ReLU"
      bottom: "res4a_branch2a"
      top: "res4a_branch2a"
    }
    layer {
      name: "res4a_branch2b"
      type: "Convolution"
      bottom: "res4a_branch2a"
      top: "res4a_branch2b"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 4
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res4a_branch2b/bn"
      type: "BatchNorm"
      bottom: "res4a_branch2b"
      top: "res4a_branch2b"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res4a_branch2b/relu"
      type: "ReLU"
      bottom: "res4a_branch2b"
      top: "res4a_branch2b"
    }
    layer {
      name: "pool4"
      type: "Pooling"
      bottom: "res4a_branch2b"
      top: "pool4"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
      }
    }
    layer {
      name: "res5a_branch2a"
      type: "Convolution"
      bottom: "pool4"
      top: "res5a_branch2a"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 512
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res5a_branch2a/bn"
      type: "BatchNorm"
      bottom: "res5a_branch2a"
      top: "res5a_branch2a"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res5a_branch2a/relu"
      type: "ReLU"
      bottom: "res5a_branch2a"
      top: "res5a_branch2a"
    }
    layer {
      name: "res5a_branch2b"
      type: "Convolution"
      bottom: "res5a_branch2a"
      top: "res5a_branch2b"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 512
        bias_term: true
        pad: 1
        kernel_size: 3
        group: 4
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "res5a_branch2b/bn"
      type: "BatchNorm"
      bottom: "res5a_branch2b"
      top: "res5a_branch2b"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "res5a_branch2b/relu"
      type: "ReLU"
      bottom: "res5a_branch2b"
      top: "res5a_branch2b"
    }
    layer {
      name: "pool6"
      type: "Pooling"
      bottom: "res5a_branch2b"
      top: "pool6"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
        pad: 0
      }
    }
    layer {
      name: "pool7"
      type: "Pooling"
      bottom: "pool6"
      top: "pool7"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
        pad: 0
      }
    }
    layer {
      name: "pool8"
      type: "Pooling"
      bottom: "pool7"
      top: "pool8"
      pooling_param {
        pool: MAX
        kernel_size: 2
        stride: 2
        pad: 0
      }
    }
    layer {
      name: "ctx_output1"
      type: "Convolution"
      bottom: "res4a_branch2b"
      top: "ctx_output1"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output1/bn"
      type: "BatchNorm"
      bottom: "ctx_output1"
      top: "ctx_output1"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "ctx_output1/relu"
      type: "ReLU"
      bottom: "ctx_output1"
      top: "ctx_output1"
    }
    layer {
      name: "ctx_output2"
      type: "Convolution"
      bottom: "res5a_branch2b"
      top: "ctx_output2"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output2/bn"
      type: "BatchNorm"
      bottom: "ctx_output2"
      top: "ctx_output2"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "ctx_output2/relu"
      type: "ReLU"
      bottom: "ctx_output2"
      top: "ctx_output2"
    }
    layer {
      name: "ctx_output3"
      type: "Convolution"
      bottom: "pool6"
      top: "ctx_output3"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output3/bn"
      type: "BatchNorm"
      bottom: "ctx_output3"
      top: "ctx_output3"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "ctx_output3/relu"
      type: "ReLU"
      bottom: "ctx_output3"
      top: "ctx_output3"
    }
    layer {
      name: "ctx_output4"
      type: "Convolution"
      bottom: "pool7"
      top: "ctx_output4"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output4/bn"
      type: "BatchNorm"
      bottom: "ctx_output4"
      top: "ctx_output4"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "ctx_output4/relu"
      type: "ReLU"
      bottom: "ctx_output4"
      top: "ctx_output4"
    }
    layer {
      name: "ctx_output5"
      type: "Convolution"
      bottom: "pool8"
      top: "ctx_output5"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 256
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output5/bn"
      type: "BatchNorm"
      bottom: "ctx_output5"
      top: "ctx_output5"
      batch_norm_param {
        moving_average_fraction: 0.99
        eps: 0.0001
        #scale_bias: true
      }
    }
    layer {
      name: "ctx_output5/relu"
      type: "ReLU"
      bottom: "ctx_output5"
      top: "ctx_output5"
    }
    layer {
      name: "ctx_output1/relu_mbox_loc"
      type: "Convolution"
      bottom: "ctx_output1"
      top: "ctx_output1/relu_mbox_loc"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 16
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output1/relu_mbox_loc_perm"
      type: "Permute"
      bottom: "ctx_output1/relu_mbox_loc"
      top: "ctx_output1/relu_mbox_loc_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output1/relu_mbox_loc_flat"
      type: "Flatten"
      bottom: "ctx_output1/relu_mbox_loc_perm"
      top: "ctx_output1/relu_mbox_loc_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output1/relu_mbox_conf"
      type: "Convolution"
      bottom: "ctx_output1"
      top: "ctx_output1/relu_mbox_conf"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 16#84
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output1/relu_mbox_conf_perm"
      type: "Permute"
      bottom: "ctx_output1/relu_mbox_conf"
      top: "ctx_output1/relu_mbox_conf_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output1/relu_mbox_conf_flat"
      type: "Flatten"
      bottom: "ctx_output1/relu_mbox_conf_perm"
      top: "ctx_output1/relu_mbox_conf_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output1/relu_mbox_priorbox"
      type: "PriorBox"
      bottom: "ctx_output1"
      bottom: "data"
      top: "ctx_output1/relu_mbox_priorbox"
      prior_box_param {
        min_size: 24 #14.72
        max_size: 50.24 #36.8
        aspect_ratio: 2
        flip: true
        clip: false
        variance: 0.1
        variance: 0.1
        variance: 0.2
        variance: 0.2
        offset: 0.5
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_loc"
      type: "Convolution"
      bottom: "ctx_output2"
      top: "ctx_output2/relu_mbox_loc"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 24
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_loc_perm"
      type: "Permute"
      bottom: "ctx_output2/relu_mbox_loc"
      top: "ctx_output2/relu_mbox_loc_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_loc_flat"
      type: "Flatten"
      bottom: "ctx_output2/relu_mbox_loc_perm"
      top: "ctx_output2/relu_mbox_loc_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_conf"
      type: "Convolution"
      bottom: "ctx_output2"
      top: "ctx_output2/relu_mbox_conf"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 24#126
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_conf_perm"
      type: "Permute"
      bottom: "ctx_output2/relu_mbox_conf"
      top: "ctx_output2/relu_mbox_conf_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_conf_flat"
      type: "Flatten"
      bottom: "ctx_output2/relu_mbox_conf_perm"
      top: "ctx_output2/relu_mbox_conf_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output2/relu_mbox_priorbox"
      type: "PriorBox"
      bottom: "ctx_output2"
      bottom: "data"
      top: "ctx_output2/relu_mbox_priorbox"
      prior_box_param {
        min_size: 50.24 #36.8
        max_size: 76.48 #110.4
        aspect_ratio: 2
        aspect_ratio: 3
        flip: true
        clip: false
        variance: 0.1
        variance: 0.1
        variance: 0.2
        variance: 0.2
        offset: 0.5
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_loc"
      type: "Convolution"
      bottom: "ctx_output3"
      top: "ctx_output3/relu_mbox_loc"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 24
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_loc_perm"
      type: "Permute"
      bottom: "ctx_output3/relu_mbox_loc"
      top: "ctx_output3/relu_mbox_loc_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_loc_flat"
      type: "Flatten"
      bottom: "ctx_output3/relu_mbox_loc_perm"
      top: "ctx_output3/relu_mbox_loc_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_conf"
      type: "Convolution"
      bottom: "ctx_output3"
      top: "ctx_output3/relu_mbox_conf"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 24#126
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_conf_perm"
      type: "Permute"
      bottom: "ctx_output3/relu_mbox_conf"
      top: "ctx_output3/relu_mbox_conf_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_conf_flat"
      type: "Flatten"
      bottom: "ctx_output3/relu_mbox_conf_perm"
      top: "ctx_output3/relu_mbox_conf_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output3/relu_mbox_priorbox"
      type: "PriorBox"
      bottom: "ctx_output3"
      bottom: "data"
      top: "ctx_output3/relu_mbox_priorbox"
      prior_box_param {
        min_size: 76.48 #110.4
        max_size: 102.72 #184.0
        aspect_ratio: 2
        aspect_ratio: 3
        flip: true
        clip: false
        variance: 0.1
        variance: 0.1
        variance: 0.2
        variance: 0.2
        offset: 0.5
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_loc"
      type: "Convolution"
      bottom: "ctx_output4"
      top: "ctx_output4/relu_mbox_loc"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 24
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_loc_perm"
      type: "Permute"
      bottom: "ctx_output4/relu_mbox_loc"
      top: "ctx_output4/relu_mbox_loc_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_loc_flat"
      type: "Flatten"
      bottom: "ctx_output4/relu_mbox_loc_perm"
      top: "ctx_output4/relu_mbox_loc_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_conf"
      type: "Convolution"
      bottom: "ctx_output4"
      top: "ctx_output4/relu_mbox_conf"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 24#126
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_conf_perm"
      type: "Permute"
      bottom: "ctx_output4/relu_mbox_conf"
      top: "ctx_output4/relu_mbox_conf_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_conf_flat"
      type: "Flatten"
      bottom: "ctx_output4/relu_mbox_conf_perm"
      top: "ctx_output4/relu_mbox_conf_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output4/relu_mbox_priorbox"
      type: "PriorBox"
      bottom: "ctx_output4"
      bottom: "data"
      top: "ctx_output4/relu_mbox_priorbox"
      prior_box_param {
        min_size: 102.72 #184.0
        max_size: 128.96 #257.6
        aspect_ratio: 2
        aspect_ratio: 3
        flip: true
        clip: false
        variance: 0.1
        variance: 0.1
        variance: 0.2
        variance: 0.2
        offset: 0.5
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_loc"
      type: "Convolution"
      bottom: "ctx_output5"
      top: "ctx_output5/relu_mbox_loc"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 16
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_loc_perm"
      type: "Permute"
      bottom: "ctx_output5/relu_mbox_loc"
      top: "ctx_output5/relu_mbox_loc_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_loc_flat"
      type: "Flatten"
      bottom: "ctx_output5/relu_mbox_loc_perm"
      top: "ctx_output5/relu_mbox_loc_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_conf"
      type: "Convolution"
      bottom: "ctx_output5"
      top: "ctx_output5/relu_mbox_conf"
      param {
        lr_mult: 1
        decay_mult: 1
      }
      param {
        lr_mult: 2
        decay_mult: 0
      }
      convolution_param {
        num_output: 16#84
        bias_term: true
        pad: 0
        kernel_size: 1
        group: 1
        stride: 1
        weight_filler {
          type: "msra"
        }
        bias_filler {
          type: "constant"
          value: 0
        }
        dilation: 1
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_conf_perm"
      type: "Permute"
      bottom: "ctx_output5/relu_mbox_conf"
      top: "ctx_output5/relu_mbox_conf_perm"
      permute_param {
        order: 0
        order: 2
        order: 3
        order: 1
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_conf_flat"
      type: "Flatten"
      bottom: "ctx_output5/relu_mbox_conf_perm"
      top: "ctx_output5/relu_mbox_conf_flat"
      flatten_param {
        axis: 1
      }
    }
    layer {
      name: "ctx_output5/relu_mbox_priorbox"
      type: "PriorBox"
      bottom: "ctx_output5"
      bottom: "data"
      top: "ctx_output5/relu_mbox_priorbox"
      prior_box_param {
        min_size: 128.96 #257.6
        max_size: 160    #331.2
        aspect_ratio: 2
        flip: true
        clip: false
        variance: 0.1
        variance: 0.1
        variance: 0.2
        variance: 0.2
        offset: 0.5
      }
    }
    layer {
      name: "mbox_loc"
      type: "Concat"
      bottom: "ctx_output1/relu_mbox_loc_flat"
      bottom: "ctx_output2/relu_mbox_loc_flat"
      bottom: "ctx_output3/relu_mbox_loc_flat"
      bottom: "ctx_output4/relu_mbox_loc_flat"
      bottom: "ctx_output5/relu_mbox_loc_flat"
      top: "mbox_loc"
      concat_param {
        axis: 1
      }
    }
    layer {
      name: "mbox_conf"
      type: "Concat"
      bottom: "ctx_output1/relu_mbox_conf_flat"
      bottom: "ctx_output2/relu_mbox_conf_flat"
      bottom: "ctx_output3/relu_mbox_conf_flat"
      bottom: "ctx_output4/relu_mbox_conf_flat"
      bottom: "ctx_output5/relu_mbox_conf_flat"
      top: "mbox_conf"
      concat_param {
        axis: 1
      }
    }
    layer {
      name: "mbox_priorbox"
      type: "Concat"
      bottom: "ctx_output1/relu_mbox_priorbox"
      bottom: "ctx_output2/relu_mbox_priorbox"
      bottom: "ctx_output3/relu_mbox_priorbox"
      bottom: "ctx_output4/relu_mbox_priorbox"
      bottom: "ctx_output5/relu_mbox_priorbox"
      top: "mbox_priorbox"
      concat_param {
        axis: 2
      }
    }
    
    layer {
      name: "mbox_conf_reshape"
      type: "Reshape"
      bottom: "mbox_conf"
      top: "mbox_conf_reshape"
      reshape_param {
        shape {
          dim: 0
          dim: -1
          dim: 4
        }
      }
    }
    layer {
      name: "mbox_conf_softmax"
      type: "Softmax"
      bottom: "mbox_conf_reshape"
      top: "mbox_conf_softmax"
      softmax_param {
        axis: 2
      }
    }
    layer {
      name: "mbox_conf_flatten"
      type: "Flatten"
      bottom: "mbox_conf_softmax"
      top: "mbox_conf_flatten"
      flatten_param {
        axis: 1
      }
    }
    
    import numpy as np  
    import sys,os  
    import cv2
    caffe_root = '/home/caffe/'
    sys.path.insert(0, caffe_root + 'python')  
    import caffe  
    import time
    
    net_file = 'ti_bsd_5little_200_400_4pr_deploy.prototxt'
    caffe_model = './snapshot/400*200_r/4pr_iter_130000.caffemodel' 
    test_dir = "./testjpg_r_1524/"
    image_outdir = "./testjpg_r_4pr_result/"
    if not os.path.exists(caffe_model):
        print("MobileNetSSD_deploy.caffemodel does not exist,")
        print("use merge_bn.py to generate it.")
        exit()
    net = caffe.Net(net_file,caffe_model,caffe.TEST)  
    caffe.set_mode_gpu()
    caffe.set_device(0)
    CLASSES = ('background',
               'car', 'person', 'bicycle')
    def preprocess(src):
        img = cv2.resize(src, (400,200))  
        #img = img - 127.5
        #img = img * 0.007843
        return img
    def postprocess(img, out):   
        h = img.shape[0]
        w = img.shape[1]
        box = out['detection_out'][0,0,:,3:7] * np.array([w, h, w, h])
        cls = out['detection_out'][0,0,:,1]
        conf = out['detection_out'][0,0,:,2]
        return (box.astype(np.int32), conf, cls)
    
    def detect(imgfile):
        file_path,file_name = os.path.split(imgfile)
        #print file_path,file_name
        start = time.time()
        origimg = cv2.imread(imgfile)
        img = preprocess(origimg)
        img = img.astype(np.float32)
        img = img.transpose((2, 0, 1))
        end = time.time()
        print ('Read image took {:.3f}s').format(  end - start)
        net.blobs['data'].data[...] = img
        start = time.time()
        out = net.forward()  
        box, conf, cls = postprocess(origimg, out)
        end = time.time()
        print ('Detection took {:.3f}s').format(  end - start)
        for i in range(len(box)):
           if (conf[i] > 0.3)&((str(CLASSES[int(cls[i])]) == "car")):  
             p1 = (box[i][0], box[i][1])
             p2 = (box[i][2], box[i][3])         
             cv2.rectangle(origimg, p1, p2, (0,255,0))
             p3 = (max(p1[0], 15), max(p1[1], 15))
             title = "%s:%.2f" % (CLASSES[int(cls[i])], conf[i])
             cv2.putText(origimg, title, p3, cv2.FONT_ITALIC, 0.3, (0, 255, 0), 1)        
           if (conf[i] > 0.3)&(str(CLASSES[int(cls[i])]) == "person"):
               p1 = (box[i][0], box[i][1])
               p2 = (box[i][2], box[i][3])         
               cv2.rectangle(origimg, p1, p2, (0,255,255))
               p3 = (max(p1[0], 15), max(p1[1], 15))
               title = "%s:%.2f" % (CLASSES[int(cls[i])], conf[i])
               cv2.putText(origimg, title, p3, cv2.FONT_ITALIC, 0.3, (0, 255, 0), 1)
           if (conf[i] > 0.3)&(str(CLASSES[int(cls[i])]) == "bicycle"):
               p1 = (box[i][0], box[i][1])
               p2 = (box[i][2], box[i][3])         
               cv2.rectangle(origimg, p1, p2, (0,255,255))
               p3 = (max(p1[0], 15), max(p1[1], 15))
               title = "%s:%.2f" % (CLASSES[int(cls[i])], conf[i])
               cv2.putText(origimg, title, p3, cv2.FONT_ITALIC, 0.3, (0, 255, 0), 1)
        #cv2.imshow("SSD", origimg)
        #k = cv2.waitKey(1) & 0xff
        cv2.imwrite(image_outdir + '/'+ file_name, origimg)    
            #Exit if ESC pressed
        #if k == 27 : return False
        return True
    
    for f in sorted(os.listdir(test_dir)):
        if detect(test_dir + "/" + f) == False:
           break
    

    caffe代码
    c++编写的深度学习框架,关注3个目录 include/src/ tools。
    Blob 是 Caffe 中处理和传递实际数据的数据封装包,并且在 CPU 与 GPU 之间具有同步处理能力。
    Layer 是 Caffe 模型的本质内容和执行计算的基本单元。Layer 可以进行很多运算,如:convolve,pool,normalize,load data,softmax losses。
    Net 是由一系列层组成的有向无环(DAG)计算图,Caffe 保留了计算图中所有的中间值以确保前向和反向迭代的准确性。一个典型的 Net 开始于 data layer——从磁盘中加载数据,终止于 loss layer——计算如分类和重构这些任务的目标函数。
    Net::Forward()和 Net::Backward()方法实现网络的前传和后传,Solver 优化一个模型,首先通过调用前传来获得输出和损失,然后调用反传产生模型的梯度,将梯度与权值更新后相结合来最小化损失。Solver、网络和层之间的分工使得 Caffe可以模块化并且开源。
    Caffe 模型的学习被分为两个部分:由 Solver 进行优化、更新参数,由 Net 计算出 loss 和 gradient。在Caffe中,损失是通过网络的前向计算得到。
    Solver 通过协调 Net 的前向推断计算和反向梯度计算(forward inference and backward gradients), 来对参数进行更新,从而达到减小 loss 的目的。Caffe 模型的学习被分为两个部分:由 Solver 进行优化、更新参数,由 Net 计算出 loss 和 gradient。
    为了创建一个 caffe 模型,我们需要在一个 protocol buffer(prototxt)文件中定义模型的结构。
    在 caffe 中,层和相应的参数都定义在 caffe.proto 文件里Caffe 有命令行、Python 和 MATLAB 三种接口,来实现日常使用、研究代码的交互以及实现快速原型。
    Caffe 中数据流以 Blobs 进行传输。数据层将输入转换为 blob 加载数据,将 blob 转换为其他格式保存输出。
    模型可视化工具
    http://ethereon.github.io/netscope/#/editor
    shift+enter