aimodelshare 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aimodelshare might be problematic. Click here for more details.

aimodelshare/aimsonnx.py CHANGED
@@ -1573,7 +1573,6 @@ def _get_sklearn_modules():
1573
1573
  return models_modules_dict
1574
1574
 
1575
1575
 
1576
-
1577
1576
  def model_from_string(model_type):
1578
1577
  models_modules_dict = _get_sklearn_modules()
1579
1578
  module = models_modules_dict[model_type]
@@ -1,4 +1,4 @@
1
- # import packages
1
+ # import packages
2
2
  import os
3
3
  import contextlib
4
4
  import boto3
@@ -27,18 +27,18 @@ class ModelPlayground:
27
27
  Parameters:
28
28
  ----------
29
29
  `model_type` : ``string``
30
- values - [ 'text' , 'image' , 'tabular' , 'video', 'audio','timeseries' ]
31
- type of model data
30
+ values - [ 'text' , 'image' , 'tabular' , 'video', 'audio','timeseries' ]
31
+ type of model data
32
32
  `classification`: ``bool, default=True``
33
33
  True [DEFAULT] if model is of Classification type with categorical target variables
34
34
  False if model is of Regression type with continuous target variables
35
35
  `private` : ``bool, default = False``
36
36
  True if model and its corresponding data is not public
37
- False [DEFAULT] if model and its corresponding data is public
37
+ False [DEFAULT] if model and its corresponding data is public
38
38
  `email_list`: ``list of string values``
39
39
  values - list including all emails of users who have access the private playground.
40
40
  list should contain same emails that were used by users to sign up for modelshare.ai account.
41
- [OPTIONAL] set by the playground owner for private playgrounds. Can also be updated by editing deployed
41
+ [OPTIONAL] set by the playground owner for private playgrounds. Can also be updated by editing deployed
42
42
  playground page at www.modelshare.ai.
43
43
  """
44
44
 
@@ -90,24 +90,24 @@ class ModelPlayground:
90
90
  Inputs : 7
91
91
  Output : model launched to an API
92
92
  detailed API info printed out
93
- Parameters:
93
+ Parameters:
94
94
  ----------
95
95
  `model_filepath` : ``string`` ends with '.onnx'
96
- value - Absolute path to model file
96
+ value - Absolute path to model file
97
97
  .onnx is the only accepted model file extension
98
98
  "example_model.onnx" filename for file in directory.
99
99
  "/User/xyz/model/example_model.onnx" absolute path to model file from local directory
100
100
  if no value is set the playground will be launched with only a placeholder prediction API.
101
101
  `preprocessor_filepath`: ``string``
102
- value - absolute path to preprocessor file
103
- "./preprocessor.zip"
102
+ value - absolute path to preprocessor file
103
+ "./preprocessor.zip"
104
104
  searches for an exported zip preprocessor file in the current directory
105
105
  file is generated using export_preprocessor function from the AI Modelshare library
106
106
  if no value is set the playground will be launched with only a placeholder prediction API.
107
107
  `y_train` : training labels for classification models.
108
108
  expects pandas dataframe of one hot encoded y train data
109
- if no value is set ... #TODO
110
- `example_data`: ``Example of X data that will be shown on the online Playground page.
109
+ if no value is set ... #TODO
110
+ `example_data`: ``Example of X data that will be shown on the online Playground page.
111
111
  if no example data is submitted, certain functionalities may be limited, including the deployment of live prediction APIs.
112
112
  Example data can be updated at a later stage, using the update_example_data() method.``
113
113
  `custom_libraries`: ``string``
@@ -121,13 +121,13 @@ class ModelPlayground:
121
121
  Set to False if you want to force ONNX conversion.
122
122
  `pyspark_support`: ``TODO``
123
123
  `model_input`: ``array_like``
124
- Required only when framework="pytorch"
124
+ Required only when framework="pytorch"
125
125
  One example of X training data in correct format.
126
-
126
+
127
127
  Returns:
128
128
  --------
129
129
  print_api_info : prints statements with generated model playground page and live prediction API details
130
- also prints steps to update the model submissions by the user/team
130
+ also prints steps to update the model submissions by the user/team
131
131
  """
132
132
 
133
133
  # test whether playground is already active
@@ -146,7 +146,7 @@ class ModelPlayground:
146
146
  if r:
147
147
  return
148
148
 
149
- # convert model to onnx
149
+ # convert model to onnx
150
150
  if onnx_timeout == False:
151
151
  force_onnx = True
152
152
  else:
@@ -252,24 +252,24 @@ class ModelPlayground:
252
252
  Inputs : 7
253
253
  Output : model launched to an API
254
254
  detailed API info printed out
255
- Parameters:
255
+ Parameters:
256
256
  ----------
257
257
  `model_filepath` : ``string`` ends with '.onnx'
258
- value - Absolute path to model file
258
+ value - Absolute path to model file
259
259
  [REQUIRED] to be set by the user
260
260
  .onnx is the only accepted model file extension
261
261
  "example_model.onnx" filename for file in directory.
262
262
  "/User/xyz/model/example_model.onnx" absolute path to model file from local directory
263
263
  `preprocessor_filepath`: ``string``
264
- value - absolute path to preprocessor file
264
+ value - absolute path to preprocessor file
265
265
  [REQUIRED] to be set by the user
266
- "./preprocessor.zip"
266
+ "./preprocessor.zip"
267
267
  searches for an exported zip preprocessor file in the current directory
268
- file is generated using export_preprocessor function from the AI Modelshare library
268
+ file is generated using export_preprocessor function from the AI Modelshare library
269
269
  `y_train` : training labels for classification models.
270
270
  [REQUIRED] for classification type models
271
271
  expects pandas dataframe of one hot encoded y train data
272
- `example_data`: ``Example of X data that will be shown on the online Playground page.
272
+ `example_data`: ``Example of X data that will be shown on the online Playground page.
273
273
  if no example data is submitted, certain functionalities may be limited, including the deployment of live prediction APIs.
274
274
  Example data can be updated at a later stage, using the update_example_data() method.``
275
275
  `custom_libraries`: ``string``
@@ -284,13 +284,13 @@ class ModelPlayground:
284
284
  Set to False if you want to force ONNX conversion.
285
285
  `pyspark_support`: ``TODO``
286
286
  `model_input`: ``array_like``
287
- Required only when framework="pytorch"
287
+ Required only when framework="pytorch"
288
288
  One example of X training data in correct format.
289
289
  `input_dict`: ``dictionary``
290
290
  Use to bypass text input boxes Example: {"model_name": "My Model Playground",
291
291
  "model_description": "My Model Description",
292
292
  "tags": "model, classification, awesome"}
293
-
293
+
294
294
  Returns:
295
295
  --------
296
296
  print_api_info : prints statements with generated live prediction API details
@@ -382,7 +382,7 @@ class ModelPlayground:
382
382
  def upload_playground_zipfile(model_filepath=None, preprocessor_filepath=None, y_train=None,
383
383
  example_data=None):
384
384
  """
385
- minimally requires model_filepath, preprocessor_filepath
385
+ minimally requires model_filepath, preprocessor_filepath
386
386
  """
387
387
  import json
388
388
  import os
@@ -628,8 +628,8 @@ class ModelPlayground:
628
628
 
629
629
  """
630
630
  Submits model/preprocessor to machine learning experiment leaderboard and model architecture database using live prediction API url generated by AI Modelshare library
631
- The submitted model gets evaluated and compared with all existing models and a leaderboard can be generated
632
-
631
+ The submitted model gets evaluated and compared with all existing models and a leaderboard can be generated
632
+
633
633
  Parameters:
634
634
  -----------
635
635
  `eval_data` : ``list`` of y values used to generate metrics from predicted values from predictions submitted via the submit_model() method
@@ -637,19 +637,19 @@ class ModelPlayground:
637
637
  `y_train` : ``list`` of y values for training data used to extract the set of class labels
638
638
  [REQUIRED] for image classification models
639
639
  `eval_metric_filepath`: [OPTIONAL] file path of zip file with custon evaluation functions
640
- `data_directory` : folder storing training data and test data (excluding Y test data)
640
+ `data_directory` : folder storing training data and test data (excluding Y test data)
641
641
  `email_list`: [OPTIONAL] list of comma separated emails for users who are allowed to submit models to experiment leaderboard. Emails should be strings in a list.
642
- `public`: [REQUIRED] True/false. Defaults to False. If True, experiment is public and ANY AIMODELSHARE USER CAN SUBMIT MODELS. USE WITH CAUTION b/c one model and
642
+ `public`: [REQUIRED] True/false. Defaults to False. If True, experiment is public and ANY AIMODELSHARE USER CAN SUBMIT MODELS. USE WITH CAUTION b/c one model and
643
643
  one preprocessor file will be be saved to your AWS S3 folder for each model submission.
644
644
  `public_private_split`: [REQUIRED] Float between 0 and 1. Defaults to 0. Porportion of test data that is allocated to private hold-out set.
645
645
  `model_input`: ``array_like``
646
- Required only when framework="pytorch"
646
+ Required only when framework="pytorch"
647
647
  One example of X training data in correct format.
648
648
  `timeout`: ``TODO``
649
649
  `onnx_timeout`: ``int``
650
650
  Time in seconds after which ONNX conversion should be interrupted.
651
651
  Set to False if you want to force ONNX conversion.
652
- `example_data`: ``Example of X data that will be shown on the online Playground page.
652
+ `example_data`: ``Example of X data that will be shown on the online Playground page.
653
653
  if no example data is submitted, certain functionalities may be limited, including the deployment of live prediction APIs.
654
654
  Example data can be updated at a later stage, using the update_example_data() method.``
655
655
 
@@ -709,7 +709,7 @@ class ModelPlayground:
709
709
  playground_id=playground_id)
710
710
  print()
711
711
 
712
- # if playground is active, ask whether user wants to overwrite
712
+ # if playground is active, ask whether user wants to overwrite
713
713
  else:
714
714
 
715
715
  print(
@@ -805,23 +805,23 @@ class ModelPlayground:
805
805
  Creates a model competition for a deployed prediction REST API
806
806
  Inputs : 4
807
807
  Output : Create ML model competition and allow authorized users to submit models to resulting leaderboard/competition
808
-
808
+
809
809
  Parameters:
810
810
  -----------
811
811
  `y_test` : ``list`` of y values for test data used to generate metrics from predicted values from X test data submitted via the submit_model() function
812
812
  [REQUIRED] to generate eval metrics in competition leaderboard
813
-
813
+
814
814
  `data_directory` : folder storing training data and test data (excluding Y test data)
815
815
  `eval_metric_filepath`: [OPTIONAL] file path of zip file with custon evaluation functions
816
816
  `email_list`: [OPTIONAL] list of comma separated emails for users who are allowed to submit models to competition. Emails should be strings in a list.
817
- `public`: [REQUIRED] True/false. Defaults to False. If True, competition is public and ANY AIMODELSHARE USER CAN SUBMIT MODELS. USE WITH CAUTION b/c one model and
817
+ `public`: [REQUIRED] True/false. Defaults to False. If True, competition is public and ANY AIMODELSHARE USER CAN SUBMIT MODELS. USE WITH CAUTION b/c one model and
818
818
  one preprocessor file will be be saved to your AWS S3 folder for each model submission.
819
819
  `public_private_split`: [REQUIRED] Float between 0 and 1. Defaults to 0.5. Porportion of test data that is allocated to private hold-out set.
820
-
820
+
821
821
  Returns:
822
822
  -----------
823
823
  finalmessage : Information such as how to submit models to competition
824
-
824
+
825
825
  """
826
826
 
827
827
  if email_list is None:
@@ -862,7 +862,7 @@ class ModelPlayground:
862
862
  # model competition files
863
863
  def upload_comp_exp_zipfile(data_directory, y_test=None, eval_metric_filepath=None, email_list=[]):
864
864
  """
865
- minimally requires model_filepath, preprocessor_filepath
865
+ minimally requires model_filepath, preprocessor_filepath
866
866
  """
867
867
  zipfilelist = [data_directory]
868
868
 
@@ -1006,24 +1006,24 @@ class ModelPlayground:
1006
1006
  Creates an experiment for a deployed prediction REST API
1007
1007
  Inputs : 4
1008
1008
  Output : Create ML model experiment and allows authorized users to submit models to resulting experiment tracking leaderboard
1009
-
1009
+
1010
1010
  Parameters:
1011
1011
  -----------
1012
1012
  `y_test` : ``list`` of y values for test data used to generate metrics from predicted values from X test data submitted via the submit_model() function
1013
1013
  [REQUIRED] to generate eval metrics in experiment leaderboard
1014
-
1014
+
1015
1015
  `data_directory` : folder storing training data and test data (excluding Y test data)
1016
1016
  `eval_metric_filepath`: [OPTIONAL] file path of zip file with custon evaluation functions
1017
1017
  `email_list`: [OPTIONAL] list of comma separated emails for users who are allowed to submit models to experiment leaderboard. Emails should be strings in a list.
1018
- `public`: [REQUIRED] True/false. Defaults to False. If True, experiment is public and ANY AIMODELSHARE USER CAN SUBMIT MODELS. USE WITH CAUTION b/c one model and
1018
+ `public`: [REQUIRED] True/false. Defaults to False. If True, experiment is public and ANY AIMODELSHARE USER CAN SUBMIT MODELS. USE WITH CAUTION b/c one model and
1019
1019
  one preprocessor file will be be saved to your AWS S3 folder for each model submission.
1020
1020
  `public_private_split`: [REQUIRED] Float between 0 and 1. Defaults to 0. Porportion of test data that is allocated to private hold-out set.
1021
-
1022
-
1021
+
1022
+
1023
1023
  Returns:
1024
1024
  -----------
1025
1025
  finalmessage : Information such as how to submit models to experiment
1026
-
1026
+
1027
1027
  """
1028
1028
 
1029
1029
  # catch email list error
@@ -1061,7 +1061,7 @@ class ModelPlayground:
1061
1061
  # model competition files
1062
1062
  def upload_comp_exp_zipfile(data_directory, y_test=None, eval_metric_filepath=None, email_list=[]):
1063
1063
  """
1064
- minimally requires model_filepath, preprocessor_filepath
1064
+ minimally requires model_filepath, preprocessor_filepath
1065
1065
  """
1066
1066
  zipfilelist = [data_directory]
1067
1067
 
@@ -1201,24 +1201,15 @@ class ModelPlayground:
1201
1201
  """
1202
1202
  Submits model/preprocessor to machine learning competition using live prediction API url generated by AI Modelshare library
1203
1203
  The submitted model gets evaluated and compared with all existing models and a leaderboard can be generated
1204
-
1204
+
1205
1205
  Parameters:
1206
1206
  -----------
1207
- `model_filepath`: ``string`` ends with '.onnx'
1208
- value - Absolute path to model file [REQUIRED] to be set by the user
1209
- .onnx is the only accepted model file extension
1210
- "example_model.onnx" filename for file in directory.
1211
- "/User/xyz/model/example_model.onnx" absolute path to model file from local directory
1207
+ `model`: model object (sklearn, keras, pytorch, onnx) or onnx model file path
1212
1208
  `prediction_submission`: one hot encoded y_pred
1213
1209
  value - predictions for test data
1214
1210
  [REQUIRED] for evaluation metrics of the submitted model
1215
- `preprocessor_filepath`: ``string``, default=None
1216
- value - absolute path to preprocessor file
1217
- [REQUIRED] to be set by the user
1218
- "./preprocessor.zip"
1219
- searches for an exported zip preprocessor file in the current directory
1220
- file is generated from preprocessor module using export_preprocessor function from the AI Modelshare library
1221
-
1211
+ `preprocessor`: preprocessor function object
1212
+
1222
1213
  Returns:
1223
1214
  --------
1224
1215
  response: Model version if the model is submitted sucessfully
@@ -1248,9 +1239,9 @@ class ModelPlayground:
1248
1239
  with HiddenPrints():
1249
1240
  competition = Competition(self.playground_url)
1250
1241
 
1251
- version_comp, model_page = competition.submit_model(model_filepath=model,
1242
+ version_comp, model_page = competition.submit_model(model=model,
1252
1243
  prediction_submission=prediction_submission,
1253
- preprocessor_filepath=preprocessor,
1244
+ preprocessor=preprocessor,
1254
1245
  reproducibility_env_filepath=reproducibility_env_filepath,
1255
1246
  custom_metadata=custom_metadata,
1256
1247
  input_dict=input_dict,
@@ -1262,9 +1253,9 @@ class ModelPlayground:
1262
1253
  with HiddenPrints():
1263
1254
  experiment = Experiment(self.playground_url)
1264
1255
 
1265
- version_exp, model_page = experiment.submit_model(model_filepath=model,
1256
+ version_exp, model_page = experiment.submit_model(model=model,
1266
1257
  prediction_submission=prediction_submission,
1267
- preprocessor_filepath=preprocessor,
1258
+ preprocessor=preprocessor,
1268
1259
  reproducibility_env_filepath=reproducibility_env_filepath,
1269
1260
  custom_metadata=custom_metadata,
1270
1261
  input_dict=input_dict,
@@ -1339,16 +1330,16 @@ class ModelPlayground:
1339
1330
 
1340
1331
  def replicate_model(self, version=None, submission_type="experiment"):
1341
1332
  """
1342
- Instantiate an untrained model with reproducibility environment setup.
1343
-
1344
- Parameters:
1333
+ Instantiate an untrained model with reproducibility environment setup.
1334
+
1335
+ Parameters:
1345
1336
  -----------
1346
1337
  `version`: ``int``
1347
1338
  Model version number from competition or experiment leaderboard
1348
-
1339
+
1349
1340
  Returns:
1350
1341
  --------
1351
- model: model chosen from leaderboard
1342
+ model: model chosen from leaderboard
1352
1343
  """
1353
1344
 
1354
1345
  model = self.instantiate_model(version=version, trained=False, reproduce=True, submission_type=submission_type)
@@ -1383,11 +1374,11 @@ class ModelPlayground:
1383
1374
  Parameters:
1384
1375
  -----------
1385
1376
  `apiurl`: string
1386
- URL of deployed prediction API
1387
-
1377
+ URL of deployed prediction API
1378
+
1388
1379
  `email_list`: [REQUIRED] list of comma separated emails for users who are allowed to submit models to competition. Emails should be strings in a list.
1389
- `update_type`:[REQUIRED] options, ``string``: 'Add', 'Remove', 'Replace_list','Get. Add appends user emails to original list, Remove deletes users from list,
1390
- 'Replace_list' overwrites the original list with the new list provided, and Get returns the current list.
1380
+ `update_type`:[REQUIRED] options, ``string``: 'Add', 'Remove', 'Replace_list','Get. Add appends user emails to original list, Remove deletes users from list,
1381
+ 'Replace_list' overwrites the original list with the new list provided, and Get returns the current list.
1391
1382
  Returns:
1392
1383
  --------
1393
1384
  response: "Success" upon successful request
@@ -1526,9 +1517,9 @@ class ModelPlayground:
1526
1517
  raise error
1527
1518
 
1528
1519
  _, api_bucket, model_id = json.loads(response.content.decode("utf-8"))
1529
- # }}}
1520
+ # }}}
1530
1521
 
1531
- # upload eval_data data:
1522
+ # upload eval_data data:
1532
1523
  eval_data_path = os.path.join(temp_dir, "ytest.pkl")
1533
1524
  import pickle
1534
1525
  # ytest data to load to s3
@@ -1553,19 +1544,19 @@ class ModelPlayground:
1553
1544
  def get_leaderboard(self, verbose=3, columns=None, submission_type="experiment"):
1554
1545
  """
1555
1546
  Get current competition leaderboard to rank all submitted models.
1556
- Use in conjuction with stylize_leaderboard to visualize data.
1557
-
1547
+ Use in conjuction with stylize_leaderboard to visualize data.
1548
+
1558
1549
  Parameters:
1559
1550
  -----------
1560
1551
  `verbose` : optional, ``int``
1561
- controls the verbosity: the higher, the more detail
1552
+ controls the verbosity: the higher, the more detail
1562
1553
  `columns` : optional, ``list of strings``
1563
1554
  list of specific column names to include in the leaderboard, all else will be excluded
1564
1555
  performance metrics will always be displayed
1565
-
1556
+
1566
1557
  Returns:
1567
1558
  --------
1568
- dictionary of leaderboard data
1559
+ dictionary of leaderboard data
1569
1560
  """
1570
1561
  from aimodelshare.leaderboard import get_leaderboard
1571
1562
  data = get_leaderboard(verbose=verbose,
@@ -1593,14 +1584,14 @@ class ModelPlayground:
1593
1584
  """
1594
1585
  Compare the structure of two or more models submitted to a competition leaderboard.
1595
1586
  Use in conjunction with stylize_compare to visualize data.
1596
-
1587
+
1597
1588
  Parameters:
1598
1589
  -----------
1599
1590
  `version_list` = ``list of int``
1600
- list of model version numbers to compare (previously submitted to competition leaderboard)
1591
+ list of model version numbers to compare (previously submitted to competition leaderboard)
1601
1592
  `verbose` = ``int``
1602
- controls the verbosity: the higher, the more detail
1603
-
1593
+ controls the verbosity: the higher, the more detail
1594
+
1604
1595
  Returns:
1605
1596
  --------
1606
1597
  data : dictionary of model comparison information
@@ -1621,10 +1612,10 @@ class ModelPlayground:
1621
1612
  Parameters:
1622
1613
  -----------
1623
1614
  `compare_dict` = dictionary of model data from compare_models
1624
-
1615
+
1625
1616
  Returns:
1626
1617
  --------
1627
- formatted table of model comparisons
1618
+ formatted table of model comparisons
1628
1619
  """
1629
1620
  from aimodelshare.aimsonnx import stylize_model_comparison
1630
1621
  stylized_compare = stylize_model_comparison(comp_dict_out=compare_dict, naming_convention=naming_convention)
@@ -1639,7 +1630,7 @@ class ModelPlayground:
1639
1630
  Model version number from competition leaderboard
1640
1631
  `trained`: ``bool, default=False``
1641
1632
  if True, a trained model is instantiated, if False, the untrained model is instantiated
1642
-
1633
+
1643
1634
  Returns:
1644
1635
  --------
1645
1636
  model: model chosen from leaderboard
@@ -1655,7 +1646,7 @@ class ModelPlayground:
1655
1646
  Parameters:
1656
1647
  ------------
1657
1648
  None
1658
-
1649
+
1659
1650
  Returns:
1660
1651
  --------
1661
1652
  dictionary of a competition's y-test metadata
@@ -1681,13 +1672,13 @@ class Competition:
1681
1672
  def __str__(self):
1682
1673
  return f"Competition class instance for playground: {self.playground_url}"
1683
1674
 
1684
- def submit_model(self, model_filepath, preprocessor_filepath, prediction_submission,
1675
+ def submit_model(self, model, preprocessor, prediction_submission,
1685
1676
  sample_data=None, reproducibility_env_filepath=None, custom_metadata=None, input_dict=None,
1686
- print_output=True):
1677
+ print_output=True, onnx_timeout=60, model_input=None):
1687
1678
  """
1688
1679
  Submits model/preprocessor to machine learning competition using live prediction API url generated by AI Modelshare library
1689
1680
  The submitted model gets evaluated and compared with all existing models and a leaderboard can be generated
1690
-
1681
+
1691
1682
  Parameters:
1692
1683
  -----------
1693
1684
  `model_filepath`: ``string`` ends with '.onnx'
@@ -1699,22 +1690,32 @@ class Competition:
1699
1690
  value - predictions for test data
1700
1691
  [REQUIRED] for evaluation metrics of the submitted model
1701
1692
  `preprocessor_filepath`: ``string``, default=None
1702
- value - absolute path to preprocessor file
1693
+ value - absolute path to preprocessor file
1703
1694
  [REQUIRED] to be set by the user
1704
- "./preprocessor.zip"
1695
+ "./preprocessor.zip"
1705
1696
  searches for an exported zip preprocessor file in the current directory
1706
- file is generated from preprocessor module using export_preprocessor function from the AI Modelshare library
1707
-
1697
+ file is generated from preprocessor module using export_preprocessor function from the AI Modelshare library
1698
+
1708
1699
  Returns:
1709
1700
  --------
1710
1701
  response: Model version if the model is submitted sucessfully
1711
1702
  """
1712
1703
 
1704
+ # convert model to onnx
1705
+ if onnx_timeout == False:
1706
+ force_onnx = True
1707
+ else:
1708
+ force_onnx = False
1709
+
1710
+ with HiddenPrints():
1711
+ model = model_to_onnx_timed(model, timeout=onnx_timeout,
1712
+ force_onnx=force_onnx, model_input=model_input)
1713
+
1713
1714
  from aimodelshare.model import submit_model
1714
- submission = submit_model(model_filepath=model_filepath,
1715
+ submission = submit_model(model_filepath=model,
1715
1716
  apiurl=self.playground_url,
1716
1717
  prediction_submission=prediction_submission,
1717
- preprocessor=preprocessor_filepath,
1718
+ preprocessor=preprocessor,
1718
1719
  reproducibility_env_filepath=reproducibility_env_filepath,
1719
1720
  custom_metadata=custom_metadata,
1720
1721
  submission_type=self.submission_type,
@@ -1732,7 +1733,7 @@ class Competition:
1732
1733
  Model version number from competition leaderboard
1733
1734
  `trained`: ``bool, default=False``
1734
1735
  if True, a trained model is instantiated, if False, the untrained model is instantiated
1735
-
1736
+
1736
1737
  Returns:
1737
1738
  --------
1738
1739
  model: model chosen from leaderboard
@@ -1744,16 +1745,16 @@ class Competition:
1744
1745
 
1745
1746
  def replicate_model(self, version=None):
1746
1747
  """
1747
- Instantiate an untrained model previously submitted to the competition leaderboard with its reproducibility environment setup.
1748
-
1749
- Parameters:
1748
+ Instantiate an untrained model previously submitted to the competition leaderboard with its reproducibility environment setup.
1749
+
1750
+ Parameters:
1750
1751
  -----------
1751
1752
  `version`: ``int``
1752
1753
  Model version number from competition or experiment leaderboard
1753
-
1754
+
1754
1755
  Returns:
1755
1756
  --------
1756
- model: model chosen from leaderboard
1757
+ model: model chosen from leaderboard
1757
1758
  """
1758
1759
 
1759
1760
  model = self.instantiate_model(version=version, trained=False, reproduce=True)
@@ -1762,15 +1763,15 @@ class Competition:
1762
1763
  def set_model_reproducibility_env(self, version=None):
1763
1764
  """
1764
1765
  Set the reproducibility environment prior to instantiating an untrained model previously submitted to the competition leaderboard.
1765
-
1766
- Parameters:
1766
+
1767
+ Parameters:
1767
1768
  -----------
1768
1769
  `version`: ``int``
1769
1770
  Model version number from competition or experiment leaderboard
1770
-
1771
+
1771
1772
  Returns:
1772
1773
  --------
1773
- Sets environment according to reproducibility.json from model if present.
1774
+ Sets environment according to reproducibility.json from model if present.
1774
1775
  """
1775
1776
  from aimodelshare.reproducibility import import_reproducibility_env_from_competition_model
1776
1777
  import_reproducibility_env_from_competition_model(apiurl=self.playground_url, version=version,
@@ -1783,7 +1784,7 @@ class Competition:
1783
1784
  ----------
1784
1785
  `version` : ``int``
1785
1786
  Model version number from competition leaderboard
1786
-
1787
+
1787
1788
  Returns:
1788
1789
  --------
1789
1790
  inspect_pd : dictionary of model summary & metadata
@@ -1799,15 +1800,15 @@ class Competition:
1799
1800
  naming_convention=None):
1800
1801
  """
1801
1802
  Compare the structure of two or more models submitted to a competition leaderboard.
1802
- Use in conjuction with stylize_compare to visualize data.
1803
-
1803
+ Use in conjuction with stylize_compare to visualize data.
1804
+
1804
1805
  Parameters:
1805
1806
  -----------
1806
1807
  `version_list` = ``list of int``
1807
- list of model version numbers to compare (previously submitted to competition leaderboard)
1808
+ list of model version numbers to compare (previously submitted to competition leaderboard)
1808
1809
  `verbose` = ``int``
1809
- controls the verbosity: the higher, the more detail
1810
-
1810
+ controls the verbosity: the higher, the more detail
1811
+
1811
1812
  Returns:
1812
1813
  --------
1813
1814
  data : dictionary of model comparison information
@@ -1828,10 +1829,10 @@ class Competition:
1828
1829
  Parameters:
1829
1830
  -----------
1830
1831
  `compare_dict` = dictionary of model data from compare_models
1831
-
1832
+
1832
1833
  Returns:
1833
1834
  --------
1834
- formatted table of model comparisons
1835
+ formatted table of model comparisons
1835
1836
  """
1836
1837
  from aimodelshare.aimsonnx import stylize_model_comparison
1837
1838
  stylized_compare = stylize_model_comparison(comp_dict_out=compare_dict, naming_convention=naming_convention)
@@ -1843,7 +1844,7 @@ class Competition:
1843
1844
  Parameters:
1844
1845
  ------------
1845
1846
  None
1846
-
1847
+
1847
1848
  Returns:
1848
1849
  --------
1849
1850
  dictionary of a competition's y-test metadata
@@ -1855,19 +1856,19 @@ class Competition:
1855
1856
  def get_leaderboard(self, verbose=3, columns=None):
1856
1857
  """
1857
1858
  Get current competition leaderboard to rank all submitted models.
1858
- Use in conjuction with stylize_leaderboard to visualize data.
1859
-
1859
+ Use in conjuction with stylize_leaderboard to visualize data.
1860
+
1860
1861
  Parameters:
1861
1862
  -----------
1862
1863
  `verbose` : optional, ``int``
1863
- controls the verbosity: the higher, the more detail
1864
+ controls the verbosity: the higher, the more detail
1864
1865
  `columns` : optional, ``list of strings``
1865
1866
  list of specific column names to include in the leaderboard, all else will be excluded
1866
1867
  performance metrics will always be displayed
1867
-
1868
+
1868
1869
  Returns:
1869
1870
  --------
1870
- dictionary of leaderboard data
1871
+ dictionary of leaderboard data
1871
1872
  """
1872
1873
  from aimodelshare.leaderboard import get_leaderboard
1873
1874
  data = get_leaderboard(verbose=verbose,
@@ -1896,11 +1897,11 @@ class Competition:
1896
1897
  Parameters:
1897
1898
  -----------
1898
1899
  `apiurl`: string
1899
- URL of deployed prediction API
1900
-
1900
+ URL of deployed prediction API
1901
+
1901
1902
  `email_list`: [REQUIRED] list of comma separated emails for users who are allowed to submit models to competition. Emails should be strings in a list.
1902
- `update_type`:[REQUIRED] options, ``string``: 'Add', 'Remove', 'Replace_list','Get. Add appends user emails to original list, Remove deletes users from list,
1903
- 'Replace_list' overwrites the original list with the new list provided, and Get returns the current list.
1903
+ `update_type`:[REQUIRED] options, ``string``: 'Add', 'Remove', 'Replace_list','Get. Add appends user emails to original list, Remove deletes users from list,
1904
+ 'Replace_list' overwrites the original list with the new list provided, and Get returns the current list.
1904
1905
  Returns:
1905
1906
  --------
1906
1907
  response: "Success" upon successful request
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aimodelshare
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Deploy locally saved machine learning models to a live rest API and web-dashboard. Share it with the world via modelshare.org
5
5
  Home-page: https://www.modelshare.org
6
6
  Author: Michael Parrott
@@ -1,6 +1,6 @@
1
1
  aimodelshare/README.md,sha256=_OMdUIeIYZnpFlKdafM1KNWaANO2nWdx0QpLE_ZC-Qs,2014
2
2
  aimodelshare/__init__.py,sha256=CS0iFxgAic21gBcQE6NSZ-D_ElHw80_A3OWrEYo9Dks,539
3
- aimodelshare/aimsonnx.py,sha256=4ZFCktqXvG2kIZyvapxZAZYo-oDxjby0ERx9zW79jg4,68709
3
+ aimodelshare/aimsonnx.py,sha256=venOx0_k8mEvDhXLZSL2Heeu04CRSIxrXHk4nf84pTY,68708
4
4
  aimodelshare/api.py,sha256=WvJnp6cdYaSycv4gpDOjstxfS3M3IANzvWli54Pcg-k,34889
5
5
  aimodelshare/aws.py,sha256=Ujhqgc1tpqdBVj5RCB_udTBt1lth4EZeLYgLU-dmu78,15188
6
6
  aimodelshare/aws_client.py,sha256=Ce19iwf69BwpuyyJlVN8z1da3c5jf93svsTgx1OWhaA,6784
@@ -15,7 +15,7 @@ aimodelshare/generatemodelapi.py,sha256=KNIWd8_g7auZi-UC-dCVmazGHJQvs9_68aGaUS47
15
15
  aimodelshare/leaderboard.py,sha256=xtKJcNCsZjy2IoK1fUTAFyM_I-eLCMS1WJRfwgsT5AA,5216
16
16
  aimodelshare/model.py,sha256=03TPnazX2s-6wjkzYl1sSpvzLOmpYW5k_2cIHZGmPgg,49899
17
17
  aimodelshare/modeluser.py,sha256=kW1zG4lFcwA0-ZLEyYaD8diJOF8PVhB-RGpPZQB07V4,4311
18
- aimodelshare/playground.py,sha256=mkuNKMbsc8UuEDTUwajIAGbP3QSRdbUr0S4vloOubbw,89026
18
+ aimodelshare/playground.py,sha256=iIPv7Na4V6Ux65xelPEsq1fdwu1SgiqGtJ2ZVhOC8oc,88269
19
19
  aimodelshare/postprocessormodules.py,sha256=L87fM2mywlInOrgaMETi-7zdHBGbIMRcrXKttQthyQ4,4992
20
20
  aimodelshare/preprocessormodules.py,sha256=ujkIdGWeMEyyc6eTaZi9kZRpfP-JEGzse89fL80ShHY,10912
21
21
  aimodelshare/readme.md,sha256=_OMdUIeIYZnpFlKdafM1KNWaANO2nWdx0QpLE_ZC-Qs,2014
@@ -142,9 +142,9 @@ aimodelshare/sam/spark-class.txt,sha256=chyJBxDzCzlUKXzVQYTzuJ2PXCTwg8_gd1yfnI-x
142
142
  aimodelshare/sam/template.txt,sha256=JKSvEOZNaaLalHSx7r9psJg_6LLCb0XLAYi1-jYPu3M,1195
143
143
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
144
144
  tests/test_aimsonnx.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
145
- tests/test_playground.py,sha256=vJW2bKfmlxfZjCP9Lud1Bvj1KEC8ELj2WheEmVcP_sk,9365
146
- aimodelshare-0.1.1.dist-info/LICENSE,sha256=JXBYLriXYgTloZs-9CJPZY76dqkuDT5df_HghMnljx8,1134
147
- aimodelshare-0.1.1.dist-info/METADATA,sha256=51EdKOwUzpoyExUPrIxrQdeQRATFT4113Hx8vRx59lo,3395
148
- aimodelshare-0.1.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
149
- aimodelshare-0.1.1.dist-info/top_level.txt,sha256=2KJgeHQ0BmZuilB75J203i7W4vri6CON2kdbwk9BNpU,19
150
- aimodelshare-0.1.1.dist-info/RECORD,,
145
+ tests/test_playground.py,sha256=fG1WSGjKkyHffHAN4vsnQ99FJqo5lreInjsN7OygGKA,12210
146
+ aimodelshare-0.1.2.dist-info/LICENSE,sha256=JXBYLriXYgTloZs-9CJPZY76dqkuDT5df_HghMnljx8,1134
147
+ aimodelshare-0.1.2.dist-info/METADATA,sha256=vwN61qr2GcDjbT8UPR8sAFXgkvhQugKEPfyOt_mz8gc,3395
148
+ aimodelshare-0.1.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
149
+ aimodelshare-0.1.2.dist-info/top_level.txt,sha256=2KJgeHQ0BmZuilB75J203i7W4vri6CON2kdbwk9BNpU,19
150
+ aimodelshare-0.1.2.dist-info/RECORD,,
tests/test_playground.py CHANGED
@@ -1,8 +1,10 @@
1
1
  from aimodelshare.playground import ModelPlayground, Experiment, Competition
2
- from aimodelshare.aws import set_credentials
2
+ from aimodelshare.aws import set_credentials, get_aws_token
3
3
  import aimodelshare as ai
4
4
  from aimodelshare.data_sharing.utils import redo_with_write
5
5
 
6
+ from unittest.mock import patch
7
+
6
8
  from sklearn.compose import ColumnTransformer
7
9
  from sklearn.pipeline import Pipeline
8
10
  from sklearn.impute import SimpleImputer
@@ -11,13 +13,14 @@ from sklearn.linear_model import LogisticRegression
11
13
 
12
14
  import pandas as pd
13
15
  import shutil
16
+ import os
14
17
 
15
18
 
16
19
 
17
20
 
18
- def test_set_credentials():
21
+ # def test_set_credentials():
19
22
 
20
- set_credentials(credential_file="../../credentials.txt", type="deploy_model")
23
+ # set_credentials(credential_file="../../credentials.txt", type="deploy_model")
21
24
 
22
25
 
23
26
  # def test_quickstart_sklearn():
@@ -32,10 +35,42 @@ def test_set_credentials():
32
35
  # assert isinstance(y_test_labels, list)
33
36
 
34
37
 
35
- def test_playground_sklearn():
38
+ def test_configure_credentials():
39
+
40
+ # mock user input
41
+ inputs = [os.environ.get('USERNAME'),
42
+ os.environ.get('PASSWORD'),
43
+ os.environ.get('AWS_ACCESS_KEY_ID'),
44
+ os.environ.get('AWS_SECRET_ACCESS_KEY'),
45
+ os.environ.get('AWS_REGION')]
46
+
47
+ with patch("getpass.getpass", side_effect=inputs):
48
+ from aimodelshare.aws import configure_credentials
49
+ configure_credentials()
50
+
51
+ # clean up credentials file
52
+ os.remove("credentials.txt")
53
+
54
+
55
+ def test_playground_sklearn():
56
+
57
+ # mock user input
58
+ inputs = [os.environ.get('USERNAME'),
59
+ os.environ.get('PASSWORD'),
60
+ os.environ.get('AWS_ACCESS_KEY_ID'),
61
+ os.environ.get('AWS_SECRET_ACCESS_KEY'),
62
+ os.environ.get('AWS_REGION')]
63
+
64
+ with patch("getpass.getpass", side_effect=inputs):
65
+ from aimodelshare.aws import configure_credentials
66
+ configure_credentials()
36
67
 
37
68
  # set credentials
38
- set_credentials(credential_file="../../credentials.txt", type="deploy_model")
69
+ set_credentials(credential_file="credentials.txt", type="deploy_model")
70
+ #os.environ["AWS_TOKEN"]=get_aws_token()
71
+
72
+ # clean up credentials file
73
+ os.remove("credentials.txt")
39
74
 
40
75
  # Get materials for tutorial
41
76
  X_train, X_test, y_train, y_test, example_data, y_test_labels = ai.import_quickstart_data("titanic")
@@ -69,7 +104,7 @@ def test_playground_sklearn():
69
104
  return preprocessed_data
70
105
 
71
106
  # check shape of X data after preprocessing it using our new function
72
- preprocessor(X_train).shape
107
+ assert preprocessor(X_train).shape == (1047, 10)
73
108
 
74
109
  # build model 1
75
110
  model = LogisticRegression(C=10, penalty='l1', solver = 'liblinear')
@@ -107,24 +142,44 @@ def test_playground_sklearn():
107
142
  input_dict={"description": "", "tags": ""},
108
143
  submission_type="all")
109
144
 
145
+ #submit model through competition
146
+ mycompetition = ai.playground.Competition(myplayground.playground_url)
147
+ mycompetition.submit_model(model=model_2,
148
+ preprocessor=preprocessor,
149
+ prediction_submission=prediction_labels,
150
+ input_dict={"description": "", "tags": ""}
151
+ )
152
+
153
+ #submit model through experiment
154
+ myexperiment = ai.playground.Experiment(myplayground.playground_url)
155
+ myexperiment.submit_model(model=model_2,
156
+ preprocessor=preprocessor,
157
+ prediction_submission=prediction_labels,
158
+ input_dict={"description": "", "tags": ""}
159
+ )
160
+
110
161
  # Check Competition Leaderboard
111
162
  data = myplayground.get_leaderboard()
112
163
  myplayground.stylize_leaderboard(data)
164
+ assert isinstance(data, pd.DataFrame)
113
165
 
114
166
  # Compare two or more models
115
- data=myplayground.compare_models([1,2], verbose=1)
167
+ data = myplayground.compare_models([1,2], verbose=1)
116
168
  myplayground.stylize_compare(data)
169
+ assert isinstance(data, (pd.DataFrame, dict))
117
170
 
118
171
  # Check structure of evaluation data
119
- myplayground.inspect_eval_data()
172
+ data = myplayground.inspect_eval_data()
173
+ assert isinstance(data, dict)
120
174
 
121
175
  # deploy model
122
176
  myplayground.deploy_model(model_version=1, example_data=example_data, y_train=y_train)
123
177
 
124
- # myplayground.update_example_data(example_data)
178
+ # update example data
179
+ myplayground.update_example_data(example_data)
125
180
 
126
- # # swap out runtime model
127
- # myplayground.update_runtime_model(model_version=1)
181
+ # swap out runtime model
182
+ myplayground.update_runtime_model(model_version=1)
128
183
 
129
184
  # delete
130
185
  myplayground.delete_deployment(confirmation=False)
@@ -135,11 +190,25 @@ def test_playground_sklearn():
135
190
 
136
191
 
137
192
 
138
- def test_playground_keras():
193
+ def test_playground_keras():
194
+
195
+ # mock user input
196
+ inputs = [os.environ.get('USERNAME'),
197
+ os.environ.get('PASSWORD'),
198
+ os.environ.get('AWS_ACCESS_KEY_ID'),
199
+ os.environ.get('AWS_SECRET_ACCESS_KEY'),
200
+ os.environ.get('AWS_REGION')]
201
+
202
+ with patch("getpass.getpass", side_effect=inputs):
203
+ from aimodelshare.aws import configure_credentials
204
+ configure_credentials()
139
205
 
140
- # Set credentials
141
- from aimodelshare.aws import set_credentials
142
- set_credentials(credential_file="../../credentials.txt", type="deploy_model")
206
+ # set credentials
207
+ set_credentials(credential_file="credentials.txt", type="deploy_model")
208
+ # os.environ["AWS_TOKEN"]=get_aws_token()
209
+
210
+ # clean up credentials file
211
+ os.remove("credentials.txt")
143
212
 
144
213
  # # Download flower image data and and pretrained Keras models
145
214
  from aimodelshare.data_sharing.download_data import import_quickstart_data
@@ -204,7 +273,7 @@ def test_playground_keras():
204
273
  from aimodelshare.playground import ModelPlayground
205
274
  myplayground=ModelPlayground(input_type="image", task_type="classification", private=False)
206
275
  # Create Model Playground Page on modelshare.ai website
207
- myplayground.create(eval_data = y_test_labels)
276
+ myplayground.create(eval_data=y_test_labels)
208
277
 
209
278
  # Submit Model to Experiment Leaderboard
210
279
  myplayground.submit_model(model=keras_model,
@@ -228,22 +297,41 @@ def test_playground_keras():
228
297
  prediction_labels = [y_train.columns[i] for i in prediction_column_index]
229
298
 
230
299
  # Submit Model 2 to Experiment Leaderboard
231
- myplayground.submit_model(model = keras_model_2,
300
+ myplayground.submit_model(model=keras_model_2,
232
301
  preprocessor=preprocessor,
233
302
  prediction_submission=prediction_labels,
234
303
  input_dict={"description": "", "tags": ""},
235
304
  submission_type="all")
236
305
 
306
+ #submit model through competition
307
+ mycompetition = ai.playground.Competition(myplayground.playground_url)
308
+ mycompetition.submit_model(model=keras_model_2,
309
+ preprocessor=preprocessor,
310
+ prediction_submission=prediction_labels,
311
+ input_dict={"description": "", "tags": ""}
312
+ )
313
+
314
+ #submit model through experiment
315
+ myexperiment = ai.playground.Experiment(myplayground.playground_url)
316
+ myexperiment.submit_model(model=keras_model_2,
317
+ preprocessor=preprocessor,
318
+ prediction_submission=prediction_labels,
319
+ input_dict={"description": "", "tags": ""}
320
+ )
321
+
237
322
  # Check experiment leaderboard
238
323
  data = myplayground.get_leaderboard()
239
324
  myplayground.stylize_leaderboard(data)
325
+ assert isinstance(data, pd.DataFrame)
240
326
 
241
327
  # Compare two or more models
242
- data=myplayground.compare_models([1,2], verbose=1)
328
+ data = myplayground.compare_models([1,2], verbose=1)
243
329
  myplayground.stylize_compare(data)
330
+ assert isinstance(data, (pd.DataFrame, dict))
244
331
 
245
332
  # Check structure of evaluation data
246
- myplayground.inspect_eval_data()
333
+ data = myplayground.inspect_eval_data()
334
+ assert isinstance(data, dict)
247
335
 
248
336
  # Update runtime model
249
337
  myplayground.update_runtime_model(model_version=2)
@@ -254,4 +342,4 @@ def test_playground_keras():
254
342
  # local cleanup
255
343
  shutil.rmtree("flower_competition_data", onerror=redo_with_write)
256
344
  shutil.rmtree("quickstart_materials", onerror=redo_with_write)
257
- shutil.rmtree("quickstart_flowers_competition", onerror=redo_with_write)
345
+ shutil.rmtree("quickstart_flowers_competition", onerror=redo_with_write)