Skip to content

Commit

Permalink
Make TensorFlow imports compatible with TF 1.14.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 289424199
  • Loading branch information
Augustin-Zidek authored and diegolascasas committed Jan 15, 2020
1 parent 3c6b08d commit 25a0bc9
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 35 deletions.
8 changes: 3 additions & 5 deletions alphafold_casp13/asa_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.
"""Class for predicting Accessible Surface Area."""

import tensorflow.compat.v1 as tf
from tensorflow.contrib import layers as contrib_layers
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import


class ASAOutputLayer(object):
Expand All @@ -26,9 +25,8 @@ def __init__(self, name='asa'):

def compute_asa_output(self, activations):
"""Just compute the logits and outputs given activations."""
asa_logits = contrib_layers.linear(
activations,
1,
asa_logits = tf.contrib.layers.linear(
activations, 1,
weights_initializer=tf.random_uniform_initializer(-0.01, 0.01),
scope='ASALogits')
self.asa_output = tf.nn.relu(asa_logits, name='ASA_output_relu')
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import numpy as np
import six
import sonnet as snt
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import

from alphafold_casp13 import config_dict
from alphafold_casp13 import contacts_experiment
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/contacts_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import enum
import json

import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import


_ProteinDescription = collections.namedtuple(
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/contacts_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Contact prediction convnet experiment example."""

from absl import logging
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import

from alphafold_casp13 import contacts_dataset
from alphafold_casp13 import contacts_network
Expand Down
27 changes: 11 additions & 16 deletions alphafold_casp13/contacts_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

from absl import logging
import sonnet
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import

from alphafold_casp13 import asa_output
from alphafold_casp13 import secstruct
from alphafold_casp13 import two_dim_convnet
from alphafold_casp13 import two_dim_resnet
from tensorflow.contrib import layers as contrib_layers


def call_on_tuple(f):
Expand Down Expand Up @@ -194,27 +193,23 @@ def compute_outputs(self, inputs_1d, residue_index, inputs_2d, crop_x, crop_y,
axis=join_dim)],
axis=collapse_dim) # Join the two crops together.
if self._collapsed_batch_norm:
embedding_1d = contrib_layers.batch_norm(
embedding_1d,
is_training=use_on_the_fly_stats,
fused=True,
decay=0.999,
scope='collapsed_batch_norm',
embedding_1d = tf.contrib.layers.batch_norm(
embedding_1d, is_training=use_on_the_fly_stats,
fused=True, decay=0.999, scope='collapsed_batch_norm',
data_format='NHWC')
for i, nfil in enumerate(self._filters_1d):
embedding_1d = contrib_layers.fully_connected(
embedding_1d = tf.contrib.layers.fully_connected(
embedding_1d,
num_outputs=nfil,
normalizer_fn=(contrib_layers.batch_norm
if self._collapsed_batch_norm else None),
normalizer_params={
'is_training': use_on_the_fly_stats,
'updates_collections': None
},
normalizer_fn=(
tf.contrib.layers.batch_norm if self._collapsed_batch_norm
else None),
normalizer_params={'is_training': use_on_the_fly_stats,
'updates_collections': None},
scope='collapsed_embed_%d' % i)

if self.torsion_multiplier > 0:
self.torsion_logits = contrib_layers.fully_connected(
self.torsion_logits = tf.contrib.layers.fully_connected(
embedding_1d,
num_outputs=self._torsion_bins * self._torsion_bins,
activation_fn=None,
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/distogram_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import numpy as np
import six.moves.cPickle as pickle
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import


RR_FORMAT = """PFRMAT RR
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/ensemble_contact_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from absl import app
from absl import flags
from absl import logging
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import

from alphafold_casp13 import distogram_io
from alphafold_casp13 import parsers
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pickle

import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import


def distance_histogram_dict(f):
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/paste_contact_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from absl import logging
import numpy as np
import six
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import

from alphafold_casp13 import distogram_io
from alphafold_casp13 import parsers
Expand Down
5 changes: 2 additions & 3 deletions alphafold_casp13/secstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

from absl import logging
import numpy as np
import tensorflow.compat.v1 as tf
from tensorflow.contrib import layers as contrib_layers
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import


# 8-class classes (Q8)
Expand Down Expand Up @@ -57,7 +56,7 @@ def make_layer_new(self, activations):
"""Make the layer."""
with tf.variable_scope(self.name, reuse=tf.AUTO_REUSE):
logging.info('Creating secstruct %s', activations)
self.logits = contrib_layers.linear(activations, self._dimension)
self.logits = tf.contrib.layers.linear(activations, self._dimension)
self.ss_q8_probs = tf.nn.softmax(self.logits)
self.ss_q3_probs = tf.matmul(
self.ss_q8_probs, tf.constant(self.q3_map_matrix, dtype=tf.float32))
Expand Down
5 changes: 2 additions & 3 deletions alphafold_casp13/two_dim_convnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"""Two dimensional convolutional neural net layers."""

from absl import logging
import tensorflow.compat.v1 as tf
from tensorflow.contrib import layers as contrib_layers
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import


def weight_variable(shape, stddev=0.01):
Expand Down Expand Up @@ -92,7 +91,7 @@ def make_conv_sep2d_layer(input_node,
def batch_norm_layer(h_conv, layer_name, is_training=True, data_format='NCHW'):
"""Batch norm layer."""
logging.vlog(1, 'batch norm for layer %s', layer_name)
return contrib_layers.batch_norm(
return tf.contrib.layers.batch_norm(
h_conv,
is_training=is_training,
fused=True,
Expand Down
2 changes: 1 addition & 1 deletion alphafold_casp13/two_dim_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""2D Resnet."""

from absl import logging
import tensorflow.compat.v1 as tf
import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import

from alphafold_casp13 import two_dim_convnet

Expand Down

0 comments on commit 25a0bc9

Please sign in to comment.