Skip to content

Commit 51c4e6e

Browse files
committed
script to upload/update model info as gist
1 parent c6827bf commit 51c4e6e

4 files changed

Lines changed: 47 additions & 16 deletions

File tree

docs/model_zoo.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Caffe Model Zoo
44

55
Lots of people have used Caffe to train models of different architectures and applied to different problems, ranging from simple regression to AlexNet-alikes to Siamese networks for image similarity to speech applications.
6-
76
To lower the friction of sharing these models, we introduce the model zoo framework:
87

98
- A standard format for packaging Caffe model info.
@@ -26,36 +25,29 @@ User-provided models are posted to a public-editable [wiki page](https://github.
2625
A caffe model is distributed as a directory containing:
2726

2827
- Solver/model prototxt(s)
29-
- Readme.md containing
28+
- `readme.md` containing
3029
- YAML frontmatter
3130
- Caffe version used to train this model (tagged release or commit hash).
3231
- [optional] file URL and SHA1 of the trained `.caffemodel`.
3332
- [optional] github gist id.
34-
- Information about what data the model was trained on, explanation of modeling choices, etc.
33+
- Information about what data the model was trained on, modeling choices, etc.
3534
- License information.
3635
- [optional] Other helpful scripts.
3736

3837
## Hosting model info
3938

4039
Github Gist is a good format for model info distribution because it can contain multiple files, is versionable, and has in-browser syntax highlighting and markdown rendering.
4140

42-
- `scripts/download_model_from_gist.sh <gist_id>`: downloads the non-binary files from a Gist into `<dirname>`
4341
- `scripts/upload_model_to_gist.sh <dirname>`: uploads non-binary files in the model directory as a Github Gist and prints the Gist ID. If `gist_id` is already part of the `<dirname>/readme.md` frontmatter, then updates existing Gist.
4442

43+
Try doing `scripts/upload_model_to_gist.sh models/bvlc_alexnet` to test the uploading (don't forget to delete the uploaded gist afterward).
44+
45+
Downloading models is not yet supported as a script (there is no good commandline tool for this right now), so simply go to the Gist URL and click "Download Gist" for now.
46+
4547
### Hosting trained models
4648

4749
It is up to the user where to host the `.caffemodel` file.
4850
We host our BVLC-provided models on our own server.
4951
Dropbox also works fine (tip: make sure that `?dl=1` is appended to the end of the URL).
5052

5153
- `scripts/download_model_binary.py <dirname>`: downloads the `.caffemodel` from the URL specified in the `<dirname>/readme.md` frontmatter and confirms SHA1.
52-
53-
54-
## Tasks
55-
56-
x get the imagenet example to work with the new prototxt location
57-
x make wiki page for user-submitted models
58-
- add flickr model to the user-submitted models wiki page
59-
x make docs section listing bvlc-distributed models
60-
- write the publish_model_as_gist script
61-
- write the download_model_from_gist script

examples/imagenet/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ Resume Training?
9191

9292
We all experience times when the power goes out, or we feel like rewarding ourself a little by playing Battlefield (does anyone still remember Quake?). Since we are snapshotting intermediate results during training, we will be able to resume from snapshots. This can be done as easy as:
9393

94-
./build/tools/caffe train --solver=examples/imagenet/imagenet_solver.prototxt --snapshot=examples/imagenet/caffe_imagenet_10000.solverstate
94+
./build/tools/caffe train --solver=models/bvlc_reference_caffenet/solver.prototxt --snapshot=models/bvlc_reference_caffenet/caffenet_train_10000.solverstate
9595

96-
where in the script `imagenet_train_10000.solverstate` is the solver state snapshot that stores all necessary information to recover the exact solver state (including the parameters, momentum history, etc).
96+
where in the script `caffenet_train_10000.solverstate` is the solver state snapshot that stores all necessary information to recover the exact solver state (including the parameters, momentum history, etc).
9797

9898
Parting Words
9999
-------------

models/finetune_flickr_style/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ caffemodel_url: http://dl.caffe.berkeleyvision.org/finetune_flickr_style.caffemo
55
license: non-commercial
66
sha1: 443ad95a61fb0b5cd3cee55951bcc1f299186b5e
77
caffe_commit: 41751046f18499b84dbaf529f64c0e664e2a09fe
8+
gist_id: 034c6ac3865563b69e60
89
---
910

1011
This model is trained exactly as described in `docs/finetune_flickr_style/readme.md`, using all 80000 images.

scripts/upload_model_to_gist.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Check for valid directory
4+
DIRNAME=$1
5+
if [ ! -f $DIRNAME/readme.md ]; then
6+
echo "usage: upload_model_to_gist.sh <dirname>"
7+
echo " <dirname>/readme.md must exist"
8+
fi
9+
cd $DIRNAME
10+
FILES=`find . -type f -maxdepth 1 ! -name "*.caffemodel*" | xargs echo`
11+
12+
# Check for gist tool.
13+
gist -v >/dev/null 2>&1 || { echo >&2 "I require 'gist' but it's not installed. Do 'gem install gist'."; exit 1; }
14+
15+
NAME=`sed -n 's/^name:[[:space:]]*//p' readme.md`
16+
if [ -z "$NAME" ]; then
17+
echo " <dirname>/readme.md must contain name field in the front-matter."
18+
fi
19+
20+
GIST=`sed -n 's/^gist_id:[[:space:]]*//p' readme.md`
21+
if [ -z "$GIST" ]; then
22+
echo "Uploading new Gist"
23+
gist -p -d "$NAME" $FILES
24+
else
25+
echo "Updating existing Gist, id $GIST"
26+
gist -u $GIST -d "$NAME" $FILES
27+
fi
28+
29+
RESULT=$?
30+
if [ $RESULT -eq 0 ]; then
31+
echo "You've uploaded your model!"
32+
echo "Don't forget to add the gist_id field to your <dirname>/readme.md now!"
33+
echo "Run the command again after you do that, to make sure the Gist id propagates."
34+
echo ""
35+
echo "And do share your model over at https://github.com/BVLC/caffe/wiki/Model-Zoo"
36+
else
37+
echo "Something went wrong!"
38+
fi

0 commit comments

Comments
 (0)