Commit b5574d2a authored by Christopher Shallue's avatar Christopher Shallue
Browse files

Replace dict.iteritems() with dict.items() for Python3 compatibility

parent f5a953c8
......@@ -130,7 +130,7 @@ class AstroCNNModel(astro_model.AstroModel):
self.time_series_hidden_layers
"""
time_series_hidden_layers = {}
for name, time_series in self.time_series_features.iteritems():
for name, time_series in self.time_series_features.items():
time_series_hidden_layers[name] = self._build_cnn_layers(
inputs=time_series,
hparams=self.hparams.time_series_hidden[name],
......
......@@ -151,7 +151,7 @@ class AstroFCModel(astro_model.AstroModel):
self.time_series_hidden_layers
"""
time_series_hidden_layers = {}
for name, time_series in self.time_series_features.iteritems():
for name, time_series in self.time_series_features.items():
time_series_hidden_layers[name] = self._build_local_fc_layers(
inputs=time_series,
hparams=self.hparams.time_series_hidden[name],
......
......@@ -180,7 +180,7 @@ def _process_tce(tce):
_set_float_feature(ex, "local_view", local_view)
# Set other columns.
for col_name, value in tce.iteritems():
for col_name, value in tce.items():
if np.issubdtype(type(value), np.integer):
_set_int64_feature(ex, col_name, [value])
else:
......
......@@ -60,7 +60,7 @@ def _recursive_pad_to_batch_size(tensor_or_collection, batch_size):
if isinstance(tensor_or_collection, dict):
return {
name: _recursive_pad_to_batch_size(t, batch_size)
for name, t in tensor_or_collection.iteritems()
for name, t in tensor_or_collection.items()
}
if isinstance(tensor_or_collection, collections.Iterable):
......@@ -197,7 +197,7 @@ def build_dataset(file_pattern,
# Set specifications for parsing the features.
data_fields = {
feature_name: tf.FixedLenFeature([feature.length], tf.float32)
for feature_name, feature in input_config.features.iteritems()
for feature_name, feature in input_config.features.items()
}
if include_labels:
data_fields[input_config.label_feature] = tf.FixedLenFeature([],
......@@ -217,7 +217,7 @@ def build_dataset(file_pattern,
# Reorganize outputs.
output = {}
for feature_name, value in parsed_features.iteritems():
for feature_name, value in parsed_features.items():
if include_labels and feature_name == input_config.label_feature:
label_id = label_to_id.lookup(value)
# Ensure that the label_id is nonnegative to verify a successful hash
......
......@@ -37,9 +37,9 @@ def prepare_feed_dict(model, features, labels=None, is_training=None):
feed_dict: A dictionary of input Tensor to numpy array.
"""
feed_dict = {}
for feature, tensor in model.time_series_features.iteritems():
for feature, tensor in model.time_series_features.items():
feed_dict[tensor] = features["time_series_features"][feature]
for feature, tensor in model.aux_features.iteritems():
for feature, tensor in model.aux_features.items():
feed_dict[tensor] = features["aux_features"][feature]
if labels is not None:
......@@ -65,7 +65,7 @@ def build_feature_placeholders(config):
"""
batch_size = None # Batch size will be dynamically specified.
features = {"time_series_features": {}, "aux_features": {}}
for feature_name, feature_spec in config.iteritems():
for feature_name, feature_spec in config.items():
placeholder = tf.placeholder(
dtype=tf.float32,
shape=[batch_size, feature_spec.length],
......
......@@ -39,7 +39,7 @@ class InputOpsTest(tf.test.TestCase):
for feature_type in features:
actual_shapes[feature_type] = {
feature: tensor.shape.as_list()
for feature, tensor in features[feature_type].iteritems()
for feature, tensor in features[feature_type].items()
}
self.assertDictEqual(expected_shapes, actual_shapes)
......
......@@ -50,11 +50,11 @@ def fake_features(feature_spec, batch_size):
features = {}
features["time_series_features"] = {
name: np.random.random([batch_size, spec["length"]])
for name, spec in feature_spec.iteritems() if spec["is_time_series"]
for name, spec in feature_spec.items() if spec["is_time_series"]
}
features["aux_features"] = {
name: np.random.random([batch_size, spec["length"]])
for name, spec in feature_spec.iteritems() if not spec["is_time_series"]
for name, spec in feature_spec.items() if not spec["is_time_series"]
}
return features
......
......@@ -110,7 +110,7 @@ def unflatten(flat_config):
A dictionary nested according to the keys of the input dictionary.
"""
config = {}
for path, value in flat_config.iteritems():
for path, value in flat_config.items():
path = path.split(".")
final_key = path.pop()
nested_config = config
......
......@@ -41,7 +41,7 @@ class ConfigDict(dict):
parameters.
"""
if initial_dictionary:
for field, value in initial_dictionary.iteritems():
for field, value in initial_dictionary.items():
initial_dictionary[field] = _maybe_convert_dict(value)
super(ConfigDict, self).__init__(initial_dictionary)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment