示例#1
0
 def test_sigmoid_cross_entropy(self):
     """Test that SigmoidCrossEntropy can be invoked."""
     batch_size = 10
     n_features = 5
     logit_tensor = np.random.rand(batch_size, n_features)
     label_tensor = np.random.randint(0, 2, (batch_size, n_features))
     with self.session() as sess:
         logit_tensor = tf.convert_to_tensor(logit_tensor, dtype=tf.float32)
         label_tensor = tf.convert_to_tensor(label_tensor, dtype=tf.float32)
         out_tensor = SigmoidCrossEntropy()(label_tensor, logit_tensor)
         out_tensor = out_tensor.eval()
         assert out_tensor.shape == (batch_size, n_features)
示例#2
0
 def test_sigmoid_cross_entropy(self):
   """Test that SigmoidCrossEntropy can be invoked."""
   batch_size = 10
   n_features = 5
   logit_tensor = np.random.rand(batch_size, n_features)
   label_tensor = np.random.randint(0, 2, (batch_size, n_features))
   with self.session() as sess:
     logit_tensor = tf.convert_to_tensor(logit_tensor, dtype=tf.float32)
     label_tensor = tf.convert_to_tensor(label_tensor, dtype=tf.float32)
     out_tensor = SigmoidCrossEntropy()(label_tensor, logit_tensor)
     out_tensor = out_tensor.eval()
     assert out_tensor.shape == (batch_size, n_features)
示例#3
0
    def build_graph(self):
        """Constructs the graph architecture of IRV as described in:

       https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2750043/
    """
        self.mol_features = Feature(shape=(None, self.n_features))
        self._labels = Label(shape=(None, self.n_tasks))
        self._weights = Weights(shape=(None, self.n_tasks))
        predictions = IRVLayer(self.n_tasks,
                               self.K,
                               in_layers=[self.mol_features])
        costs = []
        outputs = []
        for task in range(self.n_tasks):
            task_output = Slice(task, 1, in_layers=[predictions])
            sigmoid = Sigmoid(in_layers=[task_output])
            outputs.append(sigmoid)

            label = Slice(task, axis=1, in_layers=[self._labels])
            cost = SigmoidCrossEntropy(in_layers=[label, task_output])
            costs.append(cost)
        all_cost = Concat(in_layers=costs, axis=1)
        loss = WeightedError(in_layers=[all_cost, self._weights]) + \
            IRVRegularize(predictions, self.penalty, in_layers=[predictions])
        self.set_loss(loss)
        outputs = Stack(axis=1, in_layers=outputs)
        outputs = Concat(axis=2, in_layers=[1 - outputs, outputs])
        self.add_output(outputs)
示例#4
0
def test_SigmoidCrossEntropy_pickle():
  tg = TensorGraph()
  feature = Feature(shape=(tg.batch_size, 1))
  layer = SigmoidCrossEntropy(in_layers=[feature, feature])
  tg.add_output(layer)
  tg.set_loss(layer)
  tg.build()
  tg.save()