Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 8cfd621

Browse files
authored
Make inception to work with tf1.0. (#204)
1 parent b0770c7 commit 8cfd621

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

datalab/mlalpha/_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def __init__(self, file_pattern, schema=None, schema_file=None):
6161
with ml.util._file.open_local_or_gcs(schema_file, 'r') as f:
6262
self._schema = json.load(f)
6363

64-
if isinstance(files, basestring):
65-
files = [files]
66-
self._input_files = files
64+
if isinstance(file_pattern, basestring):
65+
file_pattern = [file_pattern]
66+
self._input_files = file_pattern
6767

6868
self._glob_files = []
6969

7070

7171
@property
72-
def _input_files(self):
72+
def input_files(self):
7373
"""Returns the file list that was given to this class without globing files."""
7474
return self._input_files
7575

solutionbox/inception/datalab_solutions/inception/_cloud.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
from . import _trainer
3232
from . import _util
3333

34-
35-
_TF_GS_URL= 'gs://cloud-datalab/deploy/tf/tensorflow-0.12.0rc1-cp27-none-linux_x86_64.whl'
34+
_TF_GS_URL = 'gs://cloud-datalab/deploy/tf/tensorflow-1.0.0rc1-cp27-none-linux_x86_64.whl'
3635
# Keep in sync with "data_files" in package's setup.py
3736
_SETUP_PY = '/datalab/packages_setup/inception/setup.py'
3837

@@ -68,7 +67,7 @@ def preprocess(self, train_dataset, eval_dataset, output_dir, pipeline_option):
6867
'temp_location': os.path.join(output_dir, 'tmp'),
6968
'job_name': job_name,
7069
'project': _util.default_project(),
71-
'extra_packages': [ml.sdk_location, staging_package_url, _TF_GS_URL],
70+
'extra_packages': [_TF_GS_URL, ml.version.nodeps_sdk_location, staging_package_url],
7271
'teardown_policy': 'TEARDOWN_ALWAYS',
7372
'no_save_main_session': True
7473
}
@@ -96,7 +95,7 @@ def train(self, input_dir, batch_size, max_steps, output_path, cloud_train_confi
9695
'checkpoint': self._checkpoint
9796
}
9897
job_request = {
99-
'package_uris': staging_package_url,
98+
'package_uris': [_TF_GS_URL, staging_package_url],
10099
'python_module': 'datalab_solutions.inception.task',
101100
'args': job_args
102101
}
@@ -147,7 +146,7 @@ def batch_predict(self, dataset, model_dir, gcs_staging_location, output_csv,
147146
'temp_location': os.path.join(gcs_staging_location, 'tmp'),
148147
'job_name': job_name,
149148
'project': _util.default_project(),
150-
'extra_packages': [ml.sdk_location, staging_package_url, _TF_GS_URL],
149+
'extra_packages': [_TF_GS_URL, ml.version.nodeps_sdk_location, staging_package_url],
151150
'teardown_policy': 'TEARDOWN_ALWAYS',
152151
'no_save_main_session': True
153152
}

solutionbox/inception/datalab_solutions/inception/_inceptionlib.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def inception_v3_base(inputs,
158158
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
159159
branch_3 = slim.conv2d(branch_3, depth(32), [1, 1],
160160
scope='Conv2d_0b_1x1')
161-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
161+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
162162
end_points[end_point] = net
163163
if end_point == final_endpoint: return net, end_points
164164

@@ -182,7 +182,7 @@ def inception_v3_base(inputs,
182182
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
183183
branch_3 = slim.conv2d(branch_3, depth(64), [1, 1],
184184
scope='Conv2d_0b_1x1')
185-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
185+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
186186
end_points[end_point] = net
187187
if end_point == final_endpoint: return net, end_points
188188

@@ -205,7 +205,7 @@ def inception_v3_base(inputs,
205205
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
206206
branch_3 = slim.conv2d(branch_3, depth(64), [1, 1],
207207
scope='Conv2d_0b_1x1')
208-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
208+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
209209
end_points[end_point] = net
210210
if end_point == final_endpoint: return net, end_points
211211

@@ -224,7 +224,7 @@ def inception_v3_base(inputs,
224224
with tf.variable_scope('Branch_2'):
225225
branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',
226226
scope='MaxPool_1a_3x3')
227-
net = tf.concat(3, [branch_0, branch_1, branch_2])
227+
net = tf.concat([branch_0, branch_1, branch_2], 3)
228228
end_points[end_point] = net
229229
if end_point == final_endpoint: return net, end_points
230230

@@ -253,7 +253,7 @@ def inception_v3_base(inputs,
253253
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
254254
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
255255
scope='Conv2d_0b_1x1')
256-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
256+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
257257
end_points[end_point] = net
258258
if end_point == final_endpoint: return net, end_points
259259

@@ -282,7 +282,7 @@ def inception_v3_base(inputs,
282282
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
283283
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
284284
scope='Conv2d_0b_1x1')
285-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
285+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
286286
end_points[end_point] = net
287287
if end_point == final_endpoint: return net, end_points
288288
# mixed_6: 17 x 17 x 768.
@@ -310,7 +310,7 @@ def inception_v3_base(inputs,
310310
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
311311
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
312312
scope='Conv2d_0b_1x1')
313-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
313+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
314314
end_points[end_point] = net
315315
if end_point == final_endpoint: return net, end_points
316316

@@ -339,7 +339,7 @@ def inception_v3_base(inputs,
339339
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
340340
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
341341
scope='Conv2d_0b_1x1')
342-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
342+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
343343
end_points[end_point] = net
344344
if end_point == final_endpoint: return net, end_points
345345

@@ -361,7 +361,7 @@ def inception_v3_base(inputs,
361361
with tf.variable_scope('Branch_2'):
362362
branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',
363363
scope='MaxPool_1a_3x3')
364-
net = tf.concat(3, [branch_0, branch_1, branch_2])
364+
net = tf.concat([branch_0, branch_1, branch_2], 3)
365365
end_points[end_point] = net
366366
if end_point == final_endpoint: return net, end_points
367367
# mixed_9: 8 x 8 x 2048.
@@ -371,21 +371,21 @@ def inception_v3_base(inputs,
371371
branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1')
372372
with tf.variable_scope('Branch_1'):
373373
branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1')
374-
branch_1 = tf.concat(3, [
374+
branch_1 = tf.concat([
375375
slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'),
376-
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0b_3x1')])
376+
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0b_3x1')], 3)
377377
with tf.variable_scope('Branch_2'):
378378
branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1')
379379
branch_2 = slim.conv2d(
380380
branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3')
381-
branch_2 = tf.concat(3, [
381+
branch_2 = tf.concat([
382382
slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'),
383-
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')])
383+
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')], 3)
384384
with tf.variable_scope('Branch_3'):
385385
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
386386
branch_3 = slim.conv2d(
387387
branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1')
388-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
388+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
389389
end_points[end_point] = net
390390
if end_point == final_endpoint: return net, end_points
391391

@@ -396,21 +396,21 @@ def inception_v3_base(inputs,
396396
branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1')
397397
with tf.variable_scope('Branch_1'):
398398
branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1')
399-
branch_1 = tf.concat(3, [
399+
branch_1 = tf.concat([
400400
slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'),
401-
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0c_3x1')])
401+
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0c_3x1')], 3)
402402
with tf.variable_scope('Branch_2'):
403403
branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1')
404404
branch_2 = slim.conv2d(
405405
branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3')
406-
branch_2 = tf.concat(3, [
406+
branch_2 = tf.concat([
407407
slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'),
408-
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')])
408+
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')], 3)
409409
with tf.variable_scope('Branch_3'):
410410
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
411411
branch_3 = slim.conv2d(
412412
branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1')
413-
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
413+
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
414414
end_points[end_point] = net
415415
if end_point == final_endpoint: return net, end_points
416416
raise ValueError('Unknown final endpoint %s' % final_endpoint)

solutionbox/inception/datalab_solutions/inception/_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ def decode_and_resize(image_str_tensor):
156156
image = tf.image.convert_image_dtype(image, dtype=tf.float32)
157157

158158
# Then shift images to [-1, 1) for Inception.
159-
image = tf.sub(image, 0.5)
160-
image = tf.mul(image, 2.0)
159+
image = tf.subtract(image, 0.5)
160+
image = tf.multiply(image, 2.0)
161161

162162
# Build Inception layers, which expect A tensor of type float from [-1, 1)
163163
# and shape [batch_size, height, width, channels].
@@ -325,7 +325,7 @@ def build_prediction_graph(self):
325325
# The labels are needed for client to match class scores list.
326326
labels_tensor = tf.expand_dims(tf.constant(labels), 0)
327327
num_instance = tf.shape(keys)
328-
labels_tensors_n = tf.tile(labels_tensor, tf.concat(0, [num_instance, [1]]))
328+
labels_tensors_n = tf.tile(labels_tensor, tf.concat(axis=0, values=[num_instance, [1]]))
329329

330330
outputs = {
331331
'key': keys.name,

solutionbox/inception/datalab_solutions/inception/_preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def build_graph(self):
160160
image, [self.HEIGHT, self.WIDTH], align_corners=False)
161161

162162
# Then rescale range to [-1, 1) for Inception.
163-
image = tf.sub(image, 0.5)
164-
inception_input = tf.mul(image, 2.0)
163+
image = tf.subtract(image, 0.5)
164+
inception_input = tf.multiply(image, 2.0)
165165

166166
# Build Inception layers, which expect a tensor of type float from [-1, 1)
167167
# and shape [batch_size, height, width, channels].

0 commit comments

Comments
 (0)