IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7KB

  1. #
  2. # Copyright (C) Stanislaw Adaszewski, 2020
  3. # License: GPLv3
  4. #
  5. from icosagon.input import OneHotInputLayer
  6. from icosagon.convlayer import DecagonLayer
  7. from icosagon.declayer import DecodeLayer
  8. from icosagon.decode import DEDICOMDecoder
  9. from icosagon.data import Data
  10. import torch
  11. def test_decode_layer_01():
  12. d = Data()
  13. d.add_node_type('Dummy', 100)
  14. d.add_relation_type('Dummy Relation 1', 0, 0,
  15. torch.rand((100, 100), dtype=torch.float32).round().to_sparse())
  16. in_layer = OneHotInputLayer(d)
  17. d_layer = DecagonLayer(in_layer.output_dim, 32, d)
  18. seq = torch.nn.Sequential(in_layer, d_layer)
  19. last_layer_repr = seq(None)
  20. dec = DecodeLayer(input_dim=d_layer.output_dim, data=d, keep_prob=1.,
  21. decoder_class=DEDICOMDecoder, activation=lambda x: x)
  22. pred_adj_matrices = dec(last_layer_repr)
  23. assert isinstance(pred_adj_matrices, dict)
  24. assert len(pred_adj_matrices) == 1
  25. assert isinstance(pred_adj_matrices[0, 0], list)
  26. assert len(pred_adj_matrices[0, 0]) == 1
  27. def test_decode_layer_02():
  28. d = Data()
  29. d.add_node_type('Dummy', 100)
  30. d.add_relation_type('Dummy Relation 1', 0, 0,
  31. torch.rand((100, 100), dtype=torch.float32).round().to_sparse())
  32. in_layer = OneHotInputLayer(d)
  33. d_layer = DecagonLayer(in_layer.output_dim, 32, d)
  34. dec_layer = DecodeLayer(input_dim=d_layer.output_dim, data=d, keep_prob=1.,
  35. decoder_class=DEDICOMDecoder, activation=lambda x: x)
  36. seq = torch.nn.Sequential(in_layer, d_layer, dec_layer)
  37. pred_adj_matrices = seq(None)
  38. assert isinstance(pred_adj_matrices, dict)
  39. assert len(pred_adj_matrices) == 1
  40. assert isinstance(pred_adj_matrices[0, 0], list)
  41. assert len(pred_adj_matrices[0, 0]) == 1