def test_cost_layer(self): cost1 = layer.classification_cost(input=inference, label=label) cost2 = layer.classification_cost( input=inference, label=label, weight=weight) cost3 = layer.cross_entropy_cost(input=inference, label=label) cost4 = layer.cross_entropy_with_selfnorm_cost( input=inference, label=label) cost5 = layer.square_error_cost(input=inference, label=label) cost6 = layer.square_error_cost( input=inference, label=label, weight=weight) cost7 = layer.multi_binary_label_cross_entropy_cost( input=inference, label=label) cost8 = layer.rank_cost(left=score, right=score, label=score) cost9 = layer.lambda_cost(input=inference, score=score) cost10 = layer.sum_cost(input=inference) cost11 = layer.huber_regression_cost(input=score, label=label) cost12 = layer.huber_classification_cost(input=score, label=label) print layer.parse_network([cost1, cost2]) print layer.parse_network([cost3, cost4]) print layer.parse_network([cost5, cost6]) print layer.parse_network([cost7, cost8, cost9, cost10, cost11, cost12]) crf = layer.crf(input=inference, label=label) crf_decoding = layer.crf_decoding(input=inference, size=3) ctc = layer.ctc(input=inference, label=label) warp_ctc = layer.warp_ctc(input=pixel, label=label) nce = layer.nce(input=inference, label=label, num_classes=3) hsigmoid = layer.hsigmoid(input=inference, label=label, num_classes=3) print layer.parse_network( [crf, crf_decoding, ctc, warp_ctc, nce, hsigmoid])
def test_cost_layer(self): cost1 = layer.classification_cost(input=inference, label=label) cost2 = layer.classification_cost(input=inference, label=label, weight=weight) cost3 = layer.cross_entropy_cost(input=inference, label=label) cost4 = layer.cross_entropy_with_selfnorm_cost(input=inference, label=label) cost5 = layer.mse_cost(input=inference, label=label) cost6 = layer.mse_cost(input=inference, label=label, weight=weight) cost7 = layer.multi_binary_label_cross_entropy_cost(input=inference, label=label) cost8 = layer.rank_cost(left=score, right=score, label=score) cost9 = layer.lambda_cost(input=inference, score=score) cost10 = layer.sum_cost(input=inference) cost11 = layer.huber_cost(input=score, label=label) print layer.parse_network(cost1, cost2) print layer.parse_network(cost3, cost4) print layer.parse_network(cost5, cost6) print layer.parse_network(cost7, cost8, cost9, cost10, cost11) crf = layer.crf(input=inference, label=label) crf_decoding = layer.crf_decoding(input=inference, size=3) ctc = layer.ctc(input=inference, label=label) warp_ctc = layer.warp_ctc(input=pixel, label=label) nce = layer.nce(input=inference, label=label, num_classes=3) hsigmoid = layer.hsigmoid(input=inference, label=label, num_classes=3) print layer.parse_network(crf, crf_decoding, ctc, warp_ctc, nce, hsigmoid)
def test_evaluator(self): img = layer.data(name='pixel2', type=data_type.dense_vector(784)) output = layer.fc(input=img, size=10, act=activation.Softmax(), name='fc_here') lbl = layer.data(name='label2', type=data_type.integer_value(10)) cost = layer.cross_entropy_cost(input=output, label=lbl) evaluator.classification_error(input=output, label=lbl) print layer.parse_network(cost) print layer.parse_network(output)
def test_evaluator(self): img = layer.data(name='pixel2', type=data_type.dense_vector(784)) output = layer.fc(input=img, size=10, act=activation.Softmax(), name='fc_here') lbl = layer.data(name='label2', type=data_type.integer_value(10)) cost = layer.cross_entropy_cost(input=output, label=lbl) evaluator.classification_error(input=output, label=lbl) print layer.parse_network(cost) print layer.parse_network(output)
def test_parse(self): pixel = layer.data(name='pixel3', type=data_type.dense_vector(784)) label = layer.data(name='label3', type=data_type.integer_value(10)) hidden = layer.fc(input=pixel, size=100, act=conf_helps.SigmoidActivation()) inference = layer.fc(input=hidden, size=10, act=conf_helps.SoftmaxActivation()) maxid = layer.max_id(input=inference) cost1 = layer.classification_cost(input=inference, label=label) cost2 = layer.cross_entropy_cost(input=inference, label=label) topology.Topology(cost2).proto() topology.Topology([cost1]).proto() topology.Topology([cost1, cost2]).proto() topology.Topology([inference, maxid]).proto()
def train(self): """ Trains the model. """ cls = self.network() loss = layer.cross_entropy_cost(input=cls, label=self.label, name=self.name + '_cost') evaluator_0 = paddle.evaluator.precision_recall( input=cls, name='label0', label=self.label, positive_label=0) evaluator_1 = paddle.evaluator.precision_recall( input=cls, name='label1', label=self.label, positive_label=1) evaluator_2 = paddle.evaluator.precision_recall( input=cls, name='label2', label=self.label, positive_label=2) evaluator_all = paddle.evaluator.precision_recall( input=cls, name='label_all', label=self.label) return loss
def train(self): """ Trains the model. """ cls = self.network() loss = layer.cross_entropy_cost(input=cls, label=self.label, name=self.name + '_cost') evaluator_0 = paddle.evaluator.precision_recall(input=cls, name='label0', label=self.label, positive_label=0) evaluator_1 = paddle.evaluator.precision_recall(input=cls, name='label1', label=self.label, positive_label=1) evaluator_2 = paddle.evaluator.precision_recall(input=cls, name='label2', label=self.label, positive_label=2) evaluator_all = paddle.evaluator.precision_recall(input=cls, name='label_all', label=self.label) return loss