Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用kashgari.utils.load_model 加载模型进行标签预测会报错[BUG] #304

Closed
Gjh9508 opened this issue Dec 6, 2019 · 8 comments
Closed
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@Gjh9508
Copy link

Gjh9508 commented Dec 6, 2019

You must follow the issue template and provide as much information as possible. otherwise, this issue will be closed.
请按照 issue 模板要求填写信息。如果没有按照 issue 模板填写,将会忽略并关闭这个 issue

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

You can post pictures, but if specific text or code is required to reproduce the issue, please provide the text in a plain text format for easy copy/paste.

Environment

  • OS [e.g. Mac OS, Linux]: Centos(云服务器环境)
  • Python Version: 3.6
  • requirements.txt:
  • 运行环境:tf1.14,kashgari 1.0.0
import pandas as pd
import numpy as np
import kashgari
from kashgari.tasks.classification import BiLSTM_Model
from kashgari.processors import ClassificationProcessor
from kashgari.embeddings import BareEmbedding
import logging

Issue Description

What

model.save('/output/xxx')
kashgari.utils.load_model 
loaded_model.predict(valid_x[:40])

模型在save之前可以正常使用,但是重新加载模型进行标签预测,会报错。报错信息如下:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-8ca42a11a04b> in <module>
----> 1 loaded_model.predict(valid_x[:40])

/usr/local/lib/python3.6/dist-packages/kashgari/tasks/classification/base_model.py in predict(self, x_data, batch_size, multi_label_threshold, debug_info, predict_kwargs)
     78                 pred = pred.argmax(-1)
     79 
---> 80             res = self.embedding.reverse_numerize_label_sequences(pred)
     81             if debug_info:
     82                 logging.info('input: {}'.format(tensor))

/usr/local/lib/python3.6/dist-packages/kashgari/embeddings/base_embedding.py in reverse_numerize_label_sequences(self, sequences, lengths)
    215                                          sequences,
    216                                          lengths=None):
--> 217         return self.processor.reverse_numerize_label_sequences(sequences, lengths=lengths)
    218 
    219     def __repr__(self):

/usr/local/lib/python3.6/dist-packages/kashgari/processors/classification_processor.py in reverse_numerize_label_sequences(self, sequences, **kwargs)
     82     def reverse_numerize_label_sequences(self, sequences, **kwargs):
     83         if self.multi_label:
---> 84             return self.multi_label_binarizer.inverse_transform(sequences)
     85         else:
     86             return [self.idx2label[label] for label in sequences]

AttributeError: 'NoneType' object has no attribute 'inverse_transform'

Reproduce

[The steps to reproduce this issue. What is the URL you were trying to play, where did you put your code, etc.]

Other Comment

[Add anything else here]

@Gjh9508 Gjh9508 added the bug Something isn't working label Dec 6, 2019
@BrikerMan
Copy link
Owner

谢谢反馈问题,已修复。
可以按照以下方案安装修复分支测试一下,这个分支过两天作为下一版本发布。
麻烦测试完反馈一下结果。

pip uninstall -y kashgari
pip install git+https://github.com/BrikerMan/Kashgari@fix/multi_label_classification_loading

@Gjh9508
Copy link
Author

Gjh9508 commented Dec 7, 2019

问题已经解决,谢谢!

@stale
Copy link

stale bot commented Dec 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Dec 27, 2019
@stale stale bot closed this as completed Jan 3, 2020
@sly123197811
Copy link

您好,我又遇到了相同问题,请问还没有作为最终版本修复吗,2020年5月14日11:22:18

@sly123197811
Copy link

谢谢反馈问题,已修复。
可以按照以下方案安装修复分支测试一下,这个分支过两天作为下一版本发布。
麻烦测试完反馈一下结果。

pip uninstall -y kashgari
pip install git+https://github.com/BrikerMan/Kashgari@fix/multi_label_classification_loading

您好,我最近clone的kashgari人仍然存在相同的问题,您不是说作为最终版本修复了吗?

@BrikerMan
Copy link
Owner

@sly123197811 请提供版本号信息和最小复现代码。

@sly123197811
Copy link

@sly123197811 请提供版本号信息和最小复现代码。

Python Version: 3.6
运行环境:tf1.14,kashgari-tf 0.5.5,windows10

复现代码:
modelpath = 'models/'
load_model = kashgari.utils.load_model(modelpath)
sample = list(jieba.cut(testdata))
y = load_model.predict([sample])
print(y[0])

问题跟楼主的一样

@BrikerMan
Copy link
Owner

执行以下命令更新到最新版本。

pip uninstall -y kashgari-tf
pip install kashgari

更新日志:https://kashgari.readthedocs.io/about/release-notes.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants