Commit 0e930c3f authored by Peter Eastman's avatar Peter Eastman
Browse files

Upgrade to TensorFlow 2.4

parent c6d1fb01
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -462,7 +462,7 @@ class KerasModel(Model):
    def apply_gradient_for_batch(inputs, labels, weights, loss):
      with tf.GradientTape() as tape:
        outputs = self.model(inputs, training=True)
        if isinstance(outputs, tf.Tensor):
        if tf.is_tensor(outputs):
          outputs = [outputs]
        if self._loss_outputs is not None:
          outputs = [outputs[i] for i in self._loss_outputs]
@@ -593,7 +593,7 @@ class KerasModel(Model):
          "Cannot use 'outputs' argument with a model that does not specify its inputs."
          "Note models defined in imperative subclassing style cannot specify outputs"
      )
    if isinstance(outputs, tf.Tensor):
    if tf.is_tensor(outputs):
      outputs = [outputs]
    for batch in generator:
      inputs, labels, weights = batch
@@ -612,7 +612,7 @@ class KerasModel(Model):
        output_values = self._output_functions[key](inputs)
      else:
        output_values = self._compute_model(inputs)
        if isinstance(output_values, tf.Tensor):
        if tf.is_tensor(output_values):
          output_values = [output_values]
        output_values = [t.numpy() for t in output_values]

@@ -927,7 +927,7 @@ class KerasModel(Model):
        persistent=True, watch_accessed_variables=False) as tape:
      tape.watch(X)
      outputs = self._compute_model(X)
      if isinstance(outputs, tf.Tensor):
      if tf.is_tensor(outputs):
        outputs = [outputs]
      final_result = []
      for output in outputs:
@@ -1217,7 +1217,7 @@ class _StandardLoss(object):
    losses = self.loss._compute_tf_loss(outputs[0], labels[0])
    w = weights[0]
    if len(w.shape) < len(losses.shape):
      if isinstance(w, tf.Tensor):
      if tf.is_tensor(w):
        shape = tuple(w.shape.as_list())
      else:
        shape = w.shape
+2 −10
Original line number Diff line number Diff line
@@ -36,10 +36,7 @@ class NormalizingFlow(tf.keras.models.Model):

  """

  def __init__(self,
               base_distribution,
               flow_layers: Sequence,
               event_shape: Optional[List[int]] = None,
  def __init__(self, base_distribution, flow_layers: Sequence,
               **kwargs) -> None:
    """Create a new NormalizingFlow.

@@ -50,8 +47,6 @@ class NormalizingFlow(tf.keras.models.Model):
      Typically an N dimensional multivariate Gaussian.
    flow_layers: Sequence[tfb.Bijector]
      An iterable of bijectors that comprise the flow.
    event_shape: Optional[List[int]]
      Dimensionality of inputs, e.g. [2] for 2D inputs.
    **kwargs

    """
@@ -66,16 +61,13 @@ class NormalizingFlow(tf.keras.models.Model):

    self.base_distribution = base_distribution
    self.flow_layers = flow_layers
    self.event_shape = event_shape

    # Chain of flows is also a normalizing flow
    bijector = tfb.Chain(list(reversed(self.flow_layers)))

    # An instance of tfd.TransformedDistribution
    self.flow = tfd.TransformedDistribution(
        distribution=self.base_distribution,
        bijector=bijector,
        event_shape=self.event_shape)
        distribution=self.base_distribution, bijector=bijector)

    super(NormalizingFlow, self).__init__(**kwargs)

+1 −1
Original line number Diff line number Diff line
@@ -783,7 +783,7 @@ def test_weave_singletask_regression_overfit():
      mode="regression")

  # Fit trained model
  model.fit(dataset, nb_epoch=120)
  model.fit(dataset, nb_epoch=200)

  # Eval model on train
  scores = model.evaluate(dataset, [regression_metric])
+2 −2
Original line number Diff line number Diff line
@@ -429,14 +429,14 @@ def test_IRV_multitask_classification_reload():
  reloaded_model.restore()

  # Check predictions match on random sample
  Xpred = np.random.rand(n_samples, n_features)
  Xpred = np.random.random(dataset_trans.X.shape)
  predset = dc.data.NumpyDataset(Xpred)
  origpred = model.predict(predset)
  reloadpred = reloaded_model.predict(predset)
  assert np.all(origpred == reloadpred)

  # Eval model on train
  scores = reloaded_model.evaluate(dataset, [classification_metric])
  scores = reloaded_model.evaluate(dataset_trans, [classification_metric])
  assert scores[classification_metric.name] > .9


+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ dependencies:
    - pyGPGO
    - pymatgen==2020.12.31
    - simdna
    - tensorflow==2.3.*
    - tensorflow_probability==0.11.*
    - tensorflow==2.4.*
    - tensorflow_probability==0.12.*
    - torch-geometric==1.6.*
    - transformers==3.5.*
    - xgboost==1.*