AIModelShare / aimodelshare

https://www.modelshare.org/
MIT License
38 stars 2 forks source link

Example notebook 304: Missing dependencies #193

Open SinaMostafanejad opened 2 years ago

SinaMostafanejad commented 2 years ago

Summary

The following dependency errors have been observed in Quick Start Tutorial (Start here to Deploy) hosted in the following address:

conda create -n modelshare python=3.9

Problem 1

Running the following code block

# Set credentials 
from aimodelshare.aws import set_credentials
set_credentials(credential_file="credentials.txt", type="deploy_model")

raises the following error

File .../aimodelshare/modeluser.py:10
      8 import time
      9 import datetime
---> 10 import regex as re
     11 from aimodelshare.exceptions import AuthorizationError, AWSAccessError, AWSUploadError
     13 def get_jwt_token(username, password):

ModuleNotFoundError: No module named 'regex'

Solution 1

Add the regex package to the list of dependencies when the first code block in the notebook (see below) is supposed to run

#install aimodelshare library
!  pip install aimodelshare --upgrade

Problem 2

Running the following code block after fixing Problem 1,

# Set credentials 
from aimodelshare.aws import set_credentials
set_credentials(credential_file="credentials.txt", type="deploy_model")

raises the following error

File .../aimodelshare/tools.py:2
      1 import json
...
----> 2 import pydot
      3 import argparse
      4 import datetime

ModuleNotFoundError: No module named 'pydot'

Solution 2

Add the pydot package to the list of dependencies when the first code block in the notebook is supposed to run (see Solution 1).

Problem 3

Running the following code block

# Save sklearn model to local ONNX file
from aimodelshare.aimsonnx import model_to_onnx

# Check how many preprocessed input features there are
from skl2onnx.common.data_types import FloatTensorType

feature_count=preprocessor(X_test).shape[1]
initial_type = [('float_input', FloatTensorType([None, feature_count]))]  # You need to insert correct number of preprocessed features

onnx_model = model_to_onnx(model, framework='sklearn',
                          initial_types=initial_type,
                          transfer_learning=False,deep_learning=False)

with open("model.onnx", "wb") as f:
    f.write(onnx_model.SerializeToString())

raises the following error

ModuleNotFoundError                       Traceback (most recent call last)
Cell In [12], line 2
      1 # Save sklearn model to local ONNX file
----> 2 from aimodelshare.aimsonnx import model_to_onnx
      4 # Check how many preprocessed input features there are
      5 from skl2onnx.common.data_types import FloatTensorType

File .../aimodelshare/aimsonnx.py:9
      7 from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
      8 import torch
----> 9 import xgboost
     10 import tensorflow as tf
     11 import keras

ModuleNotFoundError: No module named 'xgboost'

Solution 3

Add the xgboost package to the list of dependencies when the first code block in the notebook is supposed to run (see Solution 1).

   conda install -c conda-forge py-xgboost-gpu

Problem 4

Running the following code block

# Save sklearn model to local ONNX file
from aimodelshare.aimsonnx import model_to_onnx

# Check how many preprocessed input features there are
from skl2onnx.common.data_types import FloatTensorType

feature_count=preprocessor(X_test).shape[1]
initial_type = [('float_input', FloatTensorType([None, feature_count]))]  # You need to insert correct number of preprocessed features

onnx_model = model_to_onnx(model, framework='sklearn',
                          initial_types=initial_type,
                          transfer_learning=False,deep_learning=False)

with open("model.onnx", "wb") as f:
    f.write(onnx_model.SerializeToString())

after fixing Problem 3, raises the following error

ModuleNotFoundError                       Traceback (most recent call last)
Cell In [12], line 2
      1 # Save sklearn model to local ONNX file
----> 2 from aimodelshare.aimsonnx import model_to_onnx
      4 # Check how many preprocessed input features there are
      5 from skl2onnx.common.data_types import FloatTensorType

File .../aimodelshare/aimsonnx.py:46
     44 from IPython.core.display import display, HTML, SVG
     45 import absl.logging
---> 46 import networkx as nx
     47 import warnings
     48 from pathlib import Path

ModuleNotFoundError: No module named 'networkx'

Solution 4

Add the networkx package to the list of dependencies when the first code block in the notebook is supposed to run (see Solution 1).

Problem 5

Running the following code block

# Save sklearn model to local ONNX file
from aimodelshare.aimsonnx import model_to_onnx

# Check how many preprocessed input features there are
from skl2onnx.common.data_types import FloatTensorType

feature_count=preprocessor(X_test).shape[1]
initial_type = [('float_input', FloatTensorType([None, feature_count]))]  # You need to insert correct number of preprocessed features

onnx_model = model_to_onnx(model, framework='sklearn',
                          initial_types=initial_type,
                          transfer_learning=False,deep_learning=False)

with open("model.onnx", "wb") as f:
    f.write(onnx_model.SerializeToString())

after fixing Problem 4, raises the following error

ModuleNotFoundError: No module named 'importlib_resources'

Solution 5

Add the importlib_resources package to the list of dependencies when the first code block in the notebook is supposed to run (see Solution 1).

SinaMostafanejad commented 2 years ago

YAML file for reproducing the adopted conda environment.

environment.zip

AIModelShare commented 2 years ago

@SinaMostafanejad Thanks for the heads up on these errors. We're working on them this week and plan to have a fixed conda version deployed by next Friday.