File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525// Model represents a computer vision model configuration.
2626type Model struct {
2727 Type ModelType `yaml:"Type,omitempty" json:"type,omitempty"`
28+ Default bool `yaml:"Default,omitempty" json:"default,omitempty"`
2829 Name string `yaml:"Name,omitempty" json:"name,omitempty"`
2930 Version string `yaml:"Version,omitempty" json:"version,omitempty"`
3031 System string `yaml:"System,omitempty" json:"system,omitempty"`
Original file line number Diff line number Diff line change 99var (
1010 NasnetModel = & Model {
1111 Type : ModelTypeLabels ,
12+ Default : true ,
1213 Name : "nasnet" ,
1314 Version : VersionMobile ,
1415 Resolution : 224 ,
3940 }
4041 NsfwModel = & Model {
4142 Type : ModelTypeNsfw ,
43+ Default : true ,
4244 Name : "nsfw" ,
4345 Version : VersionLatest ,
4446 Resolution : 224 ,
6163 }
6264 FacenetModel = & Model {
6365 Type : ModelTypeFace ,
66+ Default : true ,
6467 Name : "facenet" ,
6568 Version : VersionLatest ,
6669 Resolution : 160 ,
Original file line number Diff line number Diff line change @@ -45,6 +45,33 @@ func (c *Options) Load(fileName string) error {
4545 return err
4646 }
4747
48+ // 1. Ensure that there is at least one configuration for each model type,
49+ // so that adding a copy of the default configuration to the vision.yml file
50+ // is not required. We could alternatively require a model to included in
51+ // the "vision.yml" file, but set the defaults if the "Default" flag is set.
52+ // 2. Use the default "Thresholds" if no custom thresholds are configured.
53+
54+ for i , model := range c .Models {
55+ if ! model .Default {
56+ continue
57+ }
58+
59+ switch model .Type {
60+ case ModelTypeLabels :
61+ c .Models [i ] = NasnetModel
62+ case ModelTypeNsfw :
63+ c .Models [i ] = NsfwModel
64+ case ModelTypeFace :
65+ c .Models [i ] = FacenetModel
66+ case ModelTypeCaption :
67+ c .Models [i ] = CaptionModel
68+ }
69+ }
70+
71+ if c .Thresholds .Confidence <= 0 || c .Thresholds .Confidence > 100 {
72+ c .Thresholds .Confidence = DefaultThresholds .Confidence
73+ }
74+
4875 return nil
4976}
5077
Original file line number Diff line number Diff line change 11Models :
22- Type : labels
3+ Default : true
34 Name : nasnet
45 Version : mobile
56 Resolution : 224
@@ -19,6 +20,7 @@ Models:
1920 Name : predictions/Softmax
2021 Outputs : 1000
2122- Type : nsfw
23+ Default : true
2224 Name : nsfw
2325 Version : latest
2426 Resolution : 224
@@ -33,6 +35,7 @@ Models:
3335 Name : nsfw_cls_model/final_prediction
3436 Outputs : 5
3537- Type : face
38+ Default : true
3639 Name : facenet
3740 Version : latest
3841 Resolution : 160
You can’t perform that action at this time.
0 commit comments