README.md 1.2 KB
Newer Older
R
Renwb1991 已提交
1 2 3 4 5 6 7 8
A demo to show converting caffe models trained on 'imagenet' using caffe2fluid

---

# How to use

1. Prepare python environment

S
SunAhong1993 已提交
9
2. Download caffe model to "../../models/xxx" which contains "xxx.caffemodel" and "xxx.prototxt"
R
Renwb1991 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

3. Convert the Caffe model to Fluid model
    - generate fluid code and weight file
        ```python convert.py alexnet.prototxt \
        --caffemodel alexnet.caffemodel \
        --data-output-path alexnet.npy \
        --code-output-path alexnet.py
        ```

    - save weights as fluid model file
        ```
        python alexnet.py alexnet.npy ./fluid
        ```

4. Do inference
    ```
    python infer.py infer ./fluid data/65.jpeg
    ```

5. convert model and do inference together
   ```
S
SunAhong1993 已提交
31
    bash ./tools/run.sh alexnet ../../models ../../models
R
Renwb1991 已提交
32
    ```
S
SunAhong1993 已提交
33 34
    * Assume the Caffe model is stored in '../../models/alexnet.prototxt|caffemodel*'
    * converted model will be stored as '../../models/alexnet.py|npy*'
R
Renwb1991 已提交
35 36 37

6. test the difference with caffe's results(need pycaffe installed)
   ```
S
SunAhong1993 已提交
38
    bash ./tools/diff.sh alexnet ../../models/ ../../models
R
Renwb1991 已提交
39
    ```
S
SunAhong1993 已提交
40
    * Make sure your caffemodel stored in '../../models/alexnet.prototxt|caffemodel*'
S
SunAhong1993 已提交
41
    * The results will be stored in '*./results/alexnet.paddle|caffe*'