Unverified Commit 26b924c5 authored by Bharath Ramsundar's avatar Bharath Ramsundar Committed by GitHub
Browse files

Merge pull request #1550 from peastman/deprecated

Remove uses of deprecated APIs
parents 432c951b 79366d11
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ def AtomicNNLayer(tensor, size, weights, biases, name=None):
  """

  if len(tensor.get_shape()) != 2:
    raise ValueError('Dense layer input must be 2D, not %dD' %
                     len(tensor.get_shape()))
    raise ValueError(
        'Dense layer input must be 2D, not %dD' % len(tensor.get_shape()))
  with tf.name_scope(name, 'fully_connected', [tensor, weights, biases]):
    return tf.nn.xw_plus_b(tensor, weights, biases)

@@ -111,8 +111,8 @@ def gather_neighbors(X, nbr_indices, B, N, M, d):
  example_tensors = tf.unstack(X, axis=0)
  example_nbrs = tf.unstack(nbr_indices, axis=0)
  all_nbr_coords = []
  for example, (example_tensor,
                example_nbr) in enumerate(zip(example_tensors, example_nbrs)):
  for example, (example_tensor, example_nbr) in enumerate(
      zip(example_tensors, example_nbrs)):
    nbr_coords = tf.gather(example_tensor, example_nbr)
    all_nbr_coords.append(nbr_coords)
  neighbors = tf.stack(all_nbr_coords)
@@ -149,7 +149,7 @@ def DistanceTensor(X, Nbrs, boxsize, B, N, M, d):
      nbrs_tensors = tf.unstack(nbrs, axis=1)
      for nbr, nbr_tensor in enumerate(nbrs_tensors):
        _D = tf.subtract(nbr_tensor, atom_tensor)
        _D = tf.subtract(_D, boxsize * tf.round(tf.div(_D, boxsize)))
        _D = tf.subtract(_D, boxsize * tf.round(tf.math.divide(_D, boxsize)))
        D.append(_D)
  else:
    for atom, atom_tensor in enumerate(atom_tensors):
+11 −11
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ class TensorflowGraphModel(Model):
              # non-zero weight examples in the batch.  Also, instead of using
              # tf.reduce_mean (which can put ops on the CPU) we explicitly
              # calculate with div/sum so it stays on the GPU.
              gradient_cost = tf.div(
              gradient_cost = tf.math.divide(
                  tf.reduce_sum(weighted_cost), self.batch_size)
              gradient_costs.append(gradient_cost)

@@ -416,8 +416,8 @@ class TensorflowGraphModel(Model):
    feeding and fetching the same tensor.
    """
    weights = []
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with placeholder_scope:
      for task in range(self.n_tasks):
        weights.append(
@@ -617,8 +617,8 @@ class TensorflowClassifier(TensorflowGraphModel):
    Placeholders are wrapped in identity ops to avoid the error caused by
    feeding and fetching the same tensor.
    """
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with graph.as_default():
      batch_size = self.batch_size
      n_classes = self.n_classes
@@ -770,8 +770,8 @@ class TensorflowRegressor(TensorflowGraphModel):
    Placeholders are wrapped in identity ops to avoid the error caused by
    feeding and fetching the same tensor.
    """
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with graph.as_default():
      batch_size = self.batch_size
      labels = []
@@ -859,8 +859,8 @@ class TensorflowMultiTaskRegressor(TensorflowRegressor):
        batch_size x n_features.
    """
    n_features = self.n_features
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with graph.as_default():
      with placeholder_scope:
        self.mol_features = tf.placeholder(
@@ -906,8 +906,8 @@ class TensorflowMultiTaskRegressor(TensorflowRegressor):
                    weight_init=tf.truncated_normal(
                        shape=[prev_layer_size, 1],
                        stddev=weight_init_stddevs[i]),
                    bias_init=tf.constant(value=bias_init_consts[i], shape=[1
                                                                           ]))))
                    bias_init=tf.constant(value=bias_init_consts[i],
                                          shape=[1]))))
      return output

  def construct_feed_dict(self, X_b, y_b=None, w_b=None, ids_b=None):
+7 −5
Original line number Diff line number Diff line
@@ -85,7 +85,8 @@ class MultitaskGraphClassifier(Model):
               pad_batches=True,
               verbose=True):

    warnings.warn("MultitaskGraphClassifier is deprecated. "
    warnings.warn(
        "MultitaskGraphClassifier is deprecated. "
        "Will be removed in DeepChem 1.4.", DeprecationWarning)
    super(MultitaskGraphClassifier, self).__init__(
        model_dir=logdir, verbose=verbose)
@@ -191,8 +192,9 @@ class MultitaskGraphClassifier(Model):
      task_label_vector = task_labels[task]
      task_weight_vector = task_weights[task]
      # Convert the labels into one-hot vector encodings.
      one_hot_labels = tf.to_float(
          tf.one_hot(tf.to_int32(tf.squeeze(task_label_vector)), 2))
      one_hot_labels = tf.cast(
          tf.one_hot(tf.cast(tf.squeeze(task_label_vector), tf.int32), 2),
          tf.float32)
      # Since we use tf.nn.softmax_cross_entropy_with_logits note that we pass in
      # un-softmaxed logits rather than softmax outputs.
      task_loss = loss_fn(logits[task], one_hot_labels, task_weight_vector)
@@ -200,7 +202,7 @@ class MultitaskGraphClassifier(Model):
    # It's ok to divide by just the batch_size rather than the number of nonzero
    # examples (effect averages out)
    total_loss = tf.add_n(task_losses)
    total_loss = tf.div(total_loss, self.batch_size)
    total_loss = tf.math.divide(total_loss, self.batch_size)
    return total_loss

  def add_softmax(self, outputs):
+8 −7
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ class MultitaskGraphRegressor(Model):
               pad_batches=True,
               verbose=True):

    warnings.warn("MultitaskGraphRegressor is deprecated. "
    warnings.warn(
        "MultitaskGraphRegressor is deprecated. "
        "Will be removed in DeepChem 1.4.", DeprecationWarning)

    super(MultitaskGraphRegressor, self).__init__(
@@ -154,14 +155,13 @@ class MultitaskGraphRegressor(Model):
    for task in range(self.n_tasks):
      task_label_vector = task_labels[task]
      task_weight_vector = task_weights[task]
      task_loss = loss_fn(outputs[task],
                          tf.squeeze(task_label_vector),
      task_loss = loss_fn(outputs[task], tf.squeeze(task_label_vector),
                          tf.squeeze(task_weight_vector))
      task_losses.append(task_loss)
    # It's ok to divide by just the batch_size rather than the number of nonzero
    # examples (effect averages out)
    total_loss = tf.add_n(task_losses)
    total_loss = tf.div(total_loss, self.batch_size)
    total_loss = tf.math.divide(total_loss, self.batch_size)
    return total_loss

  def fit(self,
@@ -222,7 +222,8 @@ class DTNNMultitaskGraphRegressor(MultitaskGraphRegressor):

  def build(self):
    # Create target inputs
    warnings.warn("DTNNMultitaskGraphRegressor is deprecated. "
    warnings.warn(
        "DTNNMultitaskGraphRegressor is deprecated. "
        "Will be removed in DeepChem 1.4.", DeprecationWarning)
    self.label_placeholder = tf.placeholder(
        dtype='float32', shape=(None, self.n_tasks), name="label_placeholder")
+7 −5
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ class TensorflowGraph(object):

  def __init__(self, graph, session, name_scopes, output, labels, weights,
               loss):
    warnings.warn("TensorflowGraph is deprecated. "
    warnings.warn(
        "TensorflowGraph is deprecated. "
        "Will be removed in DeepChem 1.4.", DeprecationWarning)
    self.graph = graph
    self.session = session
@@ -178,7 +179,8 @@ class TensorflowGraphModel(Model):
    seed: int
      If not none, is used as random seed for tensorflow.
    """
    warnings.warn("TensorflowGraphModel is deprecated. "
    warnings.warn(
        "TensorflowGraphModel is deprecated. "
        "Will be removed in DeepChem 1.4.", DeprecationWarning)

    # Save hyperparameters
@@ -278,7 +280,7 @@ class TensorflowGraphModel(Model):
              # non-zero weight examples in the batch.  Also, instead of using
              # tf.reduce_mean (which can put ops on the CPU) we explicitly
              # calculate with div/sum so it stays on the GPU.
              gradient_cost = tf.div(
              gradient_cost = tf.math.divide(
                  tf.reduce_sum(weighted_cost), self.batch_size)
              gradient_costs.append(gradient_cost)

Loading