2

我想用我在 azure ml 上预训练和保存的模型创建一个实验。使用此模型时,我收到此错误:

Got exception when invoking script: ''Sequential' object has no attribute '_distribution_strategy''.

它可能与已安装的库有关,但是,我不知道如何修复它。这是代码:

    import pandas as pd
    import numpy as np
    import sys
    import pickle
    import io
    import os
    os.system(f"pip install keras")
    os.system(f"pip install tensorflow=2.2")
    
    import keras
    
    from sklearn.feature_extraction.text import TfidfVectorizer
    
    def azureml_main(df, dataframe2 = None):
    
    
        sys.path.insert(0,"./Script Bundle")
        tfidf, clf = pickle.load(open("./Script Bundle/model.pkl", 'rb'))
    
        f = tfidf.transform(df.description)
       
        y_pred = clf.predict_classes(f.toarray()) ### this line causes the error
        y_probability = np.around(clf.predict_proba(f.toarray()),4)
        df_pred = pd.DataFrame(y_pred).transpose()
        df_probability = pd.DataFrame(y_probability).transpose()
            
        df_all = pd.concat([df_pred.transpose(),df_probability.transpose()],axis=1)
    
        return df_all,

希望有人可以提供帮助。

4

0 回答 0