You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

types.go 4.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. Copyright 2021 The KubeEdge Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package globalmanager
  14. import (
  15. "encoding/json"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. "k8s.io/apimachinery/pkg/runtime"
  18. "k8s.io/apimachinery/pkg/runtime/schema"
  19. )
  20. // CommonInterface describes the commom interface of CRs
  21. type CommonInterface interface {
  22. metav1.Object
  23. schema.ObjectKind
  24. runtime.Object
  25. }
  26. // FeatureControllerI defines the interface of an AI Feature controller
  27. type FeatureControllerI interface {
  28. Start() error
  29. GetName() string
  30. }
  31. type Model struct {
  32. Format string `json:"format,omitempty"`
  33. URL string `json:"url,omitempty"`
  34. Metrics map[string]interface{} `json:"metrics,omitempty"`
  35. }
  36. // the data of this condition including the input/output to do the next step
  37. type IncrementalCondData struct {
  38. Input *struct {
  39. // Only one model cases
  40. Model *Model `json:"model,omitempty"`
  41. Models []Model `json:"models,omitempty"`
  42. DataURL string `json:"dataURL,omitempty"`
  43. // the data samples reference will be stored into this URL.
  44. // The content of this url would be:
  45. // # the first uncomment line means the directory
  46. // s3://dataset/
  47. // mnist/0.jpg
  48. // mnist/1.jpg
  49. DataIndexURL string `json:"dataIndexURL,omitempty"`
  50. OutputDir string `json:"outputDir,omitempty"`
  51. } `json:"input,omitempty"`
  52. Output *struct {
  53. Model *Model `json:"model,omitempty"`
  54. Models []Model `json:"models,omitempty"`
  55. } `json:"output,omitempty"`
  56. }
  57. const (
  58. // TrainPodType is type of train pod
  59. TrainPodType = "train"
  60. // EvalPodType is type of eval pod
  61. EvalPodType = "eval"
  62. // InferencePodType is type of inference pod
  63. InferencePodType = "inference"
  64. // AnnotationsKeyPrefix defines prefix of key in annotations
  65. AnnotationsKeyPrefix = "sedna.io/"
  66. )
  67. func (m *Model) GetURL() string {
  68. return m.URL
  69. }
  70. func (cd *IncrementalCondData) joinModelURLs(model *Model, models []Model) []string {
  71. var modelURLs []string
  72. if model != nil {
  73. modelURLs = append(modelURLs, model.GetURL())
  74. } else {
  75. for _, m := range models {
  76. modelURLs = append(modelURLs, m.GetURL())
  77. }
  78. }
  79. return modelURLs
  80. }
  81. func (cd *IncrementalCondData) GetInputModelURLs() []string {
  82. return cd.joinModelURLs(cd.Input.Model, cd.Input.Models)
  83. }
  84. func (cd *IncrementalCondData) GetOutputModelURLs() []string {
  85. return cd.joinModelURLs(cd.Output.Model, cd.Output.Models)
  86. }
  87. func (cd *IncrementalCondData) Unmarshal(data []byte) error {
  88. return json.Unmarshal(data, cd)
  89. }
  90. func (cd IncrementalCondData) Marshal() ([]byte, error) {
  91. return json.Marshal(cd)
  92. }
  93. // the data of this condition including the input/output to do the next step
  94. type LifelongLearningCondData struct {
  95. Input *struct {
  96. // Only one model cases
  97. Model *Model `json:"model,omitempty"`
  98. Models []Model `json:"models,omitempty"`
  99. DataURL string `json:"dataURL,omitempty"`
  100. // the data samples reference will be stored into this URL.
  101. // The content of this url would be:
  102. // # the first uncomment line means the directory
  103. // s3://dataset/
  104. // mnist/0.jpg
  105. // mnist/1.jpg
  106. DataIndexURL string `json:"dataIndexURL,omitempty"`
  107. OutputDir string `json:"outputDir,omitempty"`
  108. } `json:"input,omitempty"`
  109. Output *struct {
  110. Model *Model `json:"model,omitempty"`
  111. Models []Model `json:"models,omitempty"`
  112. } `json:"output,omitempty"`
  113. }
  114. func (cd *LifelongLearningCondData) joinModelURLs(model *Model, models []Model) []string {
  115. var modelURLs []string
  116. if model != nil {
  117. modelURLs = append(modelURLs, model.GetURL())
  118. } else {
  119. for _, m := range models {
  120. modelURLs = append(modelURLs, m.GetURL())
  121. }
  122. }
  123. return modelURLs
  124. }
  125. func (cd *LifelongLearningCondData) Unmarshal(data []byte) error {
  126. return json.Unmarshal(data, cd)
  127. }
  128. func (cd LifelongLearningCondData) Marshal() ([]byte, error) {
  129. return json.Marshal(cd)
  130. }
  131. func (cd *LifelongLearningCondData) GetInputModelURLs() []string {
  132. return cd.joinModelURLs(cd.Input.Model, cd.Input.Models)
  133. }
  134. func (cd *LifelongLearningCondData) GetOutputModelURLs() []string {
  135. return cd.joinModelURLs(cd.Output.Model, cd.Output.Models)
  136. }