(self)
| 37 | |
| 38 | class TestLayers(LayersTestCase): |
| 39 | def testSparseDropoutWithReplacement(self): |
| 40 | input_record = schema.NewRecord(self.model.net, IdList) |
| 41 | self.model.output_schema = schema.Struct() |
| 42 | |
| 43 | lengths_blob = input_record.field_blobs()[0] |
| 44 | values_blob = input_record.field_blobs()[1] |
| 45 | lengths = np.array([1] * 10).astype(np.int32) |
| 46 | values = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.int64) |
| 47 | workspace.FeedBlob(lengths_blob, lengths) |
| 48 | workspace.FeedBlob(values_blob, values) |
| 49 | |
| 50 | out = self.model.SparseDropoutWithReplacement( |
| 51 | input_record, 0.0, 0.5, 1.0, -1, output_names_or_num=1) |
| 52 | self.assertEqual(schema.List(schema.Scalar(np.int64,)), out) |
| 53 | |
| 54 | train_init_net, train_net = self.get_training_nets() |
| 55 | eval_net = self.get_eval_net() |
| 56 | predict_net = self.get_predict_net() |
| 57 | |
| 58 | workspace.RunNetOnce(train_init_net) |
| 59 | workspace.RunNetOnce(train_net) |
| 60 | out_values = workspace.FetchBlob(out.items()) |
| 61 | out_lengths = workspace.FetchBlob(out.lengths()) |
| 62 | self.assertBlobsEqual(out_values, values) |
| 63 | self.assertBlobsEqual(out_lengths, lengths) |
| 64 | |
| 65 | workspace.RunNetOnce(eval_net) |
| 66 | |
| 67 | workspace.RunNetOnce(predict_net) |
| 68 | predict_values = workspace.FetchBlob("values_auto_0") |
| 69 | predict_lengths = workspace.FetchBlob("lengths_auto_0") |
| 70 | self.assertBlobsEqual(predict_values, np.array([-1] * 10).astype(np.int64)) |
| 71 | self.assertBlobsEqual(predict_lengths, lengths) |
| 72 | |
| 73 | def testAddLoss(self): |
| 74 | input_record_LR = self.new_record( |
nothing calls this directly
no test coverage detected