Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 05b9b32

Browse files
Add labels property to Models
1 parent 32f2ec6 commit 05b9b32

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lucid/modelzoo/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import tensorflow as tf
2121
from lucid.misc.io.reading import read
2222

23+
def load_text_labels(labels_path):
24+
return read(labels_path, encoding='utf-8').splitlines()
2325

2426
def load_graphdef(model_url, reset_device=True):
2527
"""Load GraphDef from a binary proto file."""

lucid/modelzoo/vision_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
from __future__ import absolute_import, division, print_function
1717

1818
import tensorflow as tf
19-
from lucid.modelzoo.util import load_graphdef, forget_xy
19+
from lucid.modelzoo.util import load_text_labels, load_graphdef, forget_xy
2020

2121
class Model(object):
2222
"""Base pretrained model importer."""
2323

2424
model_path = None
25+
labels_path = None
26+
labels = None
2527
image_value_range = (-1, 1)
2628
image_shape = [None, None, 3]
2729

2830
def __init__(self):
2931
self.graph_def = None
32+
if self.labels_path is not None:
33+
self.labels = load_text_labels(self.labels_path)
3034

3135
def load_graphdef(self):
3236
self.graph_def = load_graphdef(self.model_path)

lucid/modelzoo/vision_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def populate_inception_bottlenecks(scope):
3636

3737
class InceptionV1(Model):
3838
model_path = 'gs://modelzoo/InceptionV1.pb'
39+
labels_path = 'gs://modelzoo/InceptionV1-labels.txt'
3940
image_shape = [224, 224, 3]
4041
image_value_range = (-117, 255-117)
4142
input_name = 'input:0'

0 commit comments

Comments
 (0)