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

Make inception to work with tf1.0. #204

Merged
merged 1 commit into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions datalab/mlalpha/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def __init__(self, file_pattern, schema=None, schema_file=None):
with ml.util._file.open_local_or_gcs(schema_file, 'r') as f:
self._schema = json.load(f)

if isinstance(files, basestring):
files = [files]
self._input_files = files
if isinstance(file_pattern, basestring):
file_pattern = [file_pattern]
self._input_files = file_pattern

self._glob_files = []


@property
def _input_files(self):
def input_files(self):
"""Returns the file list that was given to this class without globing files."""
return self._input_files

Expand Down
9 changes: 4 additions & 5 deletions solutionbox/inception/datalab_solutions/inception/_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
from . import _trainer
from . import _util


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

Expand Down Expand Up @@ -68,7 +67,7 @@ def preprocess(self, train_dataset, eval_dataset, output_dir, pipeline_option):
'temp_location': os.path.join(output_dir, 'tmp'),
'job_name': job_name,
'project': _util.default_project(),
'extra_packages': [ml.sdk_location, staging_package_url, _TF_GS_URL],
'extra_packages': [_TF_GS_URL, ml.version.nodeps_sdk_location, staging_package_url],
'teardown_policy': 'TEARDOWN_ALWAYS',
'no_save_main_session': True
}
Expand Down Expand Up @@ -96,7 +95,7 @@ def train(self, input_dir, batch_size, max_steps, output_path, cloud_train_confi
'checkpoint': self._checkpoint
}
job_request = {
'package_uris': staging_package_url,
'package_uris': [_TF_GS_URL, staging_package_url],
'python_module': 'datalab_solutions.inception.task',
'args': job_args
}
Expand Down Expand Up @@ -147,7 +146,7 @@ def batch_predict(self, dataset, model_dir, gcs_staging_location, output_csv,
'temp_location': os.path.join(gcs_staging_location, 'tmp'),
'job_name': job_name,
'project': _util.default_project(),
'extra_packages': [ml.sdk_location, staging_package_url, _TF_GS_URL],
'extra_packages': [_TF_GS_URL, ml.version.nodeps_sdk_location, staging_package_url],
'teardown_policy': 'TEARDOWN_ALWAYS',
'no_save_main_session': True
}
Expand Down
38 changes: 19 additions & 19 deletions solutionbox/inception/datalab_solutions/inception/_inceptionlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(32), [1, 1],
scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points

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

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

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

Expand Down Expand Up @@ -253,7 +253,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points

Expand Down Expand Up @@ -282,7 +282,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points
# mixed_6: 17 x 17 x 768.
Expand Down Expand Up @@ -310,7 +310,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points

Expand Down Expand Up @@ -339,7 +339,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points

Expand All @@ -361,7 +361,7 @@ def inception_v3_base(inputs,
with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',
scope='MaxPool_1a_3x3')
net = tf.concat(3, [branch_0, branch_1, branch_2])
net = tf.concat([branch_0, branch_1, branch_2], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points
# mixed_9: 8 x 8 x 2048.
Expand All @@ -371,21 +371,21 @@ def inception_v3_base(inputs,
branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1')
with tf.variable_scope('Branch_1'):
branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1')
branch_1 = tf.concat(3, [
branch_1 = tf.concat([
slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'),
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0b_3x1')])
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0b_3x1')], 3)
with tf.variable_scope('Branch_2'):
branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d(
branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3')
branch_2 = tf.concat(3, [
branch_2 = tf.concat([
slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'),
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')])
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')], 3)
with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(
branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points

Expand All @@ -396,21 +396,21 @@ def inception_v3_base(inputs,
branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1')
with tf.variable_scope('Branch_1'):
branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1')
branch_1 = tf.concat(3, [
branch_1 = tf.concat([
slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'),
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0c_3x1')])
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0c_3x1')], 3)
with tf.variable_scope('Branch_2'):
branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d(
branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3')
branch_2 = tf.concat(3, [
branch_2 = tf.concat([
slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'),
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')])
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')], 3)
with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(
branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
end_points[end_point] = net
if end_point == final_endpoint: return net, end_points
raise ValueError('Unknown final endpoint %s' % final_endpoint)
Expand Down
6 changes: 3 additions & 3 deletions solutionbox/inception/datalab_solutions/inception/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def decode_and_resize(image_str_tensor):
image = tf.image.convert_image_dtype(image, dtype=tf.float32)

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

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

outputs = {
'key': keys.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def build_graph(self):
image, [self.HEIGHT, self.WIDTH], align_corners=False)

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

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