@@ -17,7 +17,6 @@ public sealed class OnnxModelService : IOnnxModelService
1717 {
1818 private readonly OnnxStackConfig _configuration ;
1919 private readonly ConcurrentDictionary < IOnnxModel , OnnxModelSet > _onnxModelSets ;
20- private readonly ConcurrentDictionary < IOnnxModel , IOnnxModelSetConfig > _onnxModelSetConfigs ;
2120
2221 /// <summary>
2322 /// Initializes a new instance of the <see cref="OnnxModelService"/> class.
@@ -27,7 +26,6 @@ public OnnxModelService(OnnxStackConfig configuration)
2726 {
2827 _configuration = configuration ;
2928 _onnxModelSets = new ConcurrentDictionary < IOnnxModel , OnnxModelSet > ( new OnnxModelEqualityComparer ( ) ) ;
30- _onnxModelSetConfigs = new ConcurrentDictionary < IOnnxModel , IOnnxModelSetConfig > ( new OnnxModelEqualityComparer ( ) ) ;
3129 }
3230
3331
@@ -37,65 +35,12 @@ public OnnxModelService(OnnxStackConfig configuration)
3735 public IEnumerable < OnnxModelSet > ModelSets => _onnxModelSets . Values ;
3836
3937
40- /// <summary>
41- /// Gets the ModelSet configs.
42- /// </summary>
43- public IEnumerable < IOnnxModelSetConfig > ModelSetConfigs => _onnxModelSetConfigs . Values ;
44-
45-
46- /// <summary>
47- /// Adds a model set.
48- /// </summary>
49- /// <param name="modelSet">The model set.</param>
50- /// <returns></returns>
51- public Task < bool > AddModelSet ( IOnnxModelSetConfig modelSet )
52- {
53- return Task . FromResult ( _onnxModelSetConfigs . TryAdd ( modelSet , modelSet ) ) ;
54- }
55-
56- /// <summary>
57- /// Adds a modelsets.
58- /// </summary>
59- /// <param name="modelSets">The model sets.</param>
60- public Task AddModelSet ( IEnumerable < IOnnxModelSetConfig > modelSets )
61- {
62- foreach ( var modelSet in modelSets )
63- {
64- AddModelSet ( modelSet ) ;
65- }
66- return Task . CompletedTask ;
67- }
68-
69-
70- /// <summary>
71- /// Removes the model set.
72- /// </summary>
73- /// <param name="modelSet">The model set.</param>
74- /// <returns></returns>
75- public Task < bool > RemoveModelSet ( IOnnxModelSetConfig modelSet )
76- {
77- return Task . FromResult ( _onnxModelSetConfigs . TryRemove ( modelSet , out _ ) ) ;
78- }
79-
80-
81- /// <summary>
82- /// Updates an existing model set.
83- /// </summary>
84- /// <param name="modelSet">The model set.</param>
85- /// <returns></returns>
86- public Task < bool > UpdateModelSet ( IOnnxModelSetConfig modelSet )
87- {
88- _onnxModelSetConfigs . TryRemove ( modelSet , out _ ) ;
89- return Task . FromResult ( _onnxModelSetConfigs . TryAdd ( modelSet , modelSet ) ) ;
90- }
91-
92-
9338 /// <summary>
9439 /// Loads the model.
9540 /// </summary>
9641 /// <param name="model">The model.</param>
9742 /// <returns></returns>
98- public async Task < OnnxModelSet > LoadModelAsync ( IOnnxModel model )
43+ public async Task < OnnxModelSet > LoadModelAsync ( IOnnxModelSetConfig model )
9944 {
10045 return await Task . Run ( ( ) => LoadModelSet ( model ) ) . ConfigureAwait ( false ) ;
10146 }
@@ -264,19 +209,16 @@ private OnnxModelSet GetModelSet(IOnnxModel model)
264209 /// <param name="model">The model.</param>
265210 /// <returns></returns>
266211 /// <exception cref="System.Exception">Model {model.Name} not found in configuration</exception>
267- private OnnxModelSet LoadModelSet ( IOnnxModel model )
212+ private OnnxModelSet LoadModelSet ( IOnnxModelSetConfig modelSetConfig )
268213 {
269- if ( _onnxModelSets . ContainsKey ( model ) )
270- return _onnxModelSets [ model ] ;
271-
272- if ( ! _onnxModelSetConfigs . TryGetValue ( model , out var modelSetConfig ) )
273- throw new Exception ( $ "Model { model . Name } not found") ;
274-
214+ if ( _onnxModelSets . ContainsKey ( modelSetConfig ) )
215+ return _onnxModelSets [ modelSetConfig ] ;
216+
275217 if ( ! modelSetConfig . IsEnabled )
276- throw new Exception ( $ "Model { model . Name } is not enabled") ;
218+ throw new Exception ( $ "Model { modelSetConfig . Name } is not enabled") ;
277219
278220 var modelSet = new OnnxModelSet ( modelSetConfig ) ;
279- _onnxModelSets . TryAdd ( model , modelSet ) ;
221+ _onnxModelSets . TryAdd ( modelSetConfig , modelSet ) ;
280222 return modelSet ;
281223 }
282224
0 commit comments