Skip to content

Commit 3e739a4

Browse files
committed
Add notebook.
1 parent 6d83839 commit 3e739a4

File tree

13 files changed

+598
-5
lines changed

13 files changed

+598
-5
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.ipynb filter=clean_ipynb

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ vis/
55
log/
66
pretrained/
77

8-
.idea/
8+
.ipynb_checkpoints
9+
10+
ADE_val*.jpg
11+
ADE_val*.png
12+
13+
.idea/

demo_test.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
# Image and model names
44
TEST_IMG=ADE_val_00001519.jpg
5-
MODEL_PATH=ade20k-resnet50dilated-ppm_deepsup
5+
MODEL_NAME=ade20k-resnet50dilated-ppm_deepsup
6+
MODEL_PATH=ckpt/$MODEL_NAME
67
RESULT_PATH=./
78

8-
ENCODER=$MODEL_PATH/encoder_epoch_20.pth
9-
DECODER=$MODEL_PATH/decoder_epoch_20.pth
9+
ENCODER=$MODEL_NAME/encoder_epoch_20.pth
10+
DECODER=$MODEL_NAME/decoder_epoch_20.pth
1011

1112
# Download model weights and image
1213
if [ ! -e $MODEL_PATH ]; then
13-
mkdir $MODEL_PATH
14+
mkdir -p $MODEL_PATH
1415
fi
1516
if [ ! -e $ENCODER ]; then
1617
wget -P $MODEL_PATH http://sceneparsing.csail.mit.edu/model/pytorch/$ENCODER

notebooks/ADE_val_00001519.png

514 KB
Loading

notebooks/DemoSegmenter.ipynb

Lines changed: 271 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/ckpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../ckpt

notebooks/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../config

notebooks/data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../data

notebooks/ipynb_drop_output.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Suppress output and prompt numbers in git version control.
5+
6+
This script will tell git to ignore prompt numbers and cell output
7+
when looking at ipynb files UNLESS their metadata contains:
8+
9+
"git" : { "keep_output" : true }
10+
11+
The notebooks themselves are not changed.
12+
13+
See also this blogpost: http://pascalbugnion.net/blog/ipython-notebooks-and-git.html.
14+
15+
Usage instructions
16+
==================
17+
18+
1. Put this script in a directory that is on the system's path.
19+
For future reference, I will assume you saved it in
20+
`~/scripts/ipynb_drop_output`.
21+
2. Make sure it is executable by typing the command
22+
`chmod +x ~/scripts/ipynb_drop_output`.
23+
3. Register a filter for ipython notebooks by
24+
putting the following line in `~/.config/git/attributes`:
25+
`*.ipynb filter=clean_ipynb`
26+
4. Connect this script to the filter by running the following
27+
git commands:
28+
29+
git config --global filter.clean_ipynb.clean ipynb_drop_output
30+
git config --global filter.clean_ipynb.smudge cat
31+
32+
To tell git NOT to ignore the output and prompts for a notebook,
33+
open the notebook's metadata (Edit > Edit Notebook Metadata). A
34+
panel should open containing the lines:
35+
36+
{
37+
"name" : "",
38+
"signature" : "some very long hash"
39+
}
40+
41+
Add an extra line so that the metadata now looks like:
42+
43+
{
44+
"name" : "",
45+
"signature" : "don't change the hash, but add a comma at the end of the line",
46+
"git" : { "keep_outputs" : true }
47+
}
48+
49+
You may need to "touch" the notebooks for git to actually register a change, if
50+
your notebooks are already under version control.
51+
52+
Notes
53+
=====
54+
55+
Changed by David Bau to make stripping output the default.
56+
57+
This script is inspired by http://stackoverflow.com/a/20844506/827862, but
58+
lets the user specify whether the ouptut of a notebook should be kept
59+
in the notebook's metadata, and works for IPython v3.0.
60+
"""
61+
62+
import sys
63+
import json
64+
65+
nb = sys.stdin.read()
66+
67+
json_in = json.loads(nb)
68+
nb_metadata = json_in["metadata"]
69+
keep_output = False
70+
if "git" in nb_metadata:
71+
if "keep_outputs" in nb_metadata["git"] and nb_metadata["git"]["keep_outputs"]:
72+
keep_output = True
73+
if keep_output:
74+
sys.stdout.write(nb)
75+
exit()
76+
77+
78+
ipy_version = int(json_in["nbformat"])-1 # nbformat is 1 more than actual version.
79+
80+
def strip_output_from_cell(cell):
81+
if "outputs" in cell:
82+
cell["outputs"] = []
83+
if "prompt_number" in cell:
84+
del cell["prompt_number"]
85+
if "execution_count" in cell:
86+
cell["execution_count"] = None
87+
88+
89+
if ipy_version == 2:
90+
for sheet in json_in["worksheets"]:
91+
for cell in sheet["cells"]:
92+
strip_output_from_cell(cell)
93+
else:
94+
for cell in json_in["cells"]:
95+
strip_output_from_cell(cell)
96+
97+
json.dump(json_in, sys.stdout, sort_keys=True, indent=1, separators=(",",": "))

notebooks/mit_semseg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mit_semseg

0 commit comments

Comments
 (0)