Pythonの「tensorflow」がうまく利用できません。
pip install tensorflowなどを行い、pathを通したはずですがうまくいきません。
数日前までは、添付画像のようにモジュール警告の線が引かれているのにも関わらず実行できました。
しかし、現在は実行を行っても、エラーになります。
エラー文は以下となります。
TypeError: Unable to convert function return value to a Python type! The signature was
() -> handle
また、Tracebackの内容は以下です。
Traceback (most recent call last):
File "c:\Users\K21060066\Desktop\Python学習ファイル\自然言語処理入門\chapter09\models.py", line 1, in <module>
from tensorflow.keras.models import Model
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow_init_.py", line 37, in <module>
from tensorflow.python.tools import module_util as module_util
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python_init.py", line 42, in <module>
from tensorflow.python import data
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data_init_.py", line 21, in <module>
from tensorflow.python.data import experimental
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\experimental_init_.py", line 95, in <module>
from tensorflow.python.data.experimental import service
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\experimental\service_init_.py", line 387, in <module>
from tensorflow.python.data.experimental.ops.data_service_ops import distribute
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\experimental\ops\data_service_ops.py", line 23, in <module>
from tensorflow.python.data.experimental.ops import compression_ops
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\experimental\ops\compression_ops.py", line 16, in <module>
from tensorflow.python.data.util import structure
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\util\structure.py", line 22, in <module>
from tensorflow.python.data.util import nest
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\data\util\nest.py", line 36, in <module>
from tensorflow.python.framework import sparse_tensor as _sparse_tensor
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\framework\sparse_tensor.py", line 24, in <module>
from tensorflow.python.framework import constant_op
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\framework\constant_op.py", line 25, in <module>
from tensorflow.python.eager import execute
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\eager\execute.py", line 23, in <module>
from tensorflow.python.framework import dtypes
File "C:\Users\K21060066\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\framework\dtypes.py", line 29, in <module>
_np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
TypeError: Unable to convert function return value to a Python type! The signature was
() -> handle
ライブラリのtensorflow付近のリストは以下のようになっています。
もし、この辺に精通している方がいらしましたら、ぜひご教授ください。
また、現在はanacondaの利用はできないのでご容赦ください。
python
#models.py from tensorflow.keras.models import Model from tensorflow.keras.layers import Dense, Input, Embedding, SimpleRNN, LSTM, Conv1D, GlobalMaxPooling1D class RNNModel: def __init__(self, input_dim, output_dim, emb_dim=300, hid_dim=100, embeddings=None, trainable=True): self.input = Input(shape=(None,), name='input') if embeddings is None: self.embedding = Embedding(input_dim=input_dim, output_dim=emb_dim, mask_zero=True, trainable=trainable, name='embedding') else: self.embedding = Embedding(input_dim=embeddings.shape[0], output_dim=embeddings.shape[1], mask_zero=True, trainable=trainable, weights=[embeddings], name='embedding') self.rnn = SimpleRNN(hid_dim, name='rnn') self.fc = Dense(output_dim, activation='softmax') def build(self): x = self.input embedding = self.embedding(x) output = self.rnn(embedding) y = self.fc(output) return Model(inputs=x, outputs=y) class LSTMModel: def __init__(self, input_dim, output_dim, emb_dim=300, hid_dim=100, embeddings=None, trainable=True): self.input = Input(shape=(None,), name='input') if embeddings is None: self.embedding = Embedding(input_dim=input_dim, output_dim=emb_dim, mask_zero=True, trainable=trainable, name='embedding') else: self.embedding = Embedding(input_dim=embeddings.shape[0], output_dim=embeddings.shape[1], mask_zero=True, trainable=trainable, weights=[embeddings], name='embedding') self.lstm = LSTM(hid_dim, name='lstm') self.fc = Dense(output_dim, activation='softmax') def build(self): x = self.input embedding = self.embedding(x) output = self.lstm(embedding) y = self.fc(output) return Model(inputs=x, outputs=y) class CNNModel: def __init__(self, input_dim, output_dim, filters=250, kernel_size=3, emb_dim=300, embeddings=None, trainable=True): self.input = Input(shape=(None,), name='input') if embeddings is None: self.embedding = Embedding(input_dim=input_dim, output_dim=emb_dim, trainable=trainable, name='embedding') else: self.embedding = Embedding(input_dim=embeddings.shape[0], output_dim=embeddings.shape[1], trainable=trainable, weights=[embeddings], name='embedding') self.conv = Conv1D(filters, kernel_size, padding='valid', activation='relu', strides=1) self.pool = GlobalMaxPooling1D() self.fc = Dense(output_dim, activation='softmax') def build(self): x = self.input embedding = self.embedding(x) conv = self.conv(embedding) pool = self.pool(conv) y = self.fc(pool) return Model(inputs=x, outputs=y) class LSTMCNNModel: def __init__(self, input_dim, output_dim, filters=250, kernel_size=3, emb_dim=300, hid_dim=100, embeddings=None): self.input = Input(shape=(None,), name='input') if embeddings is None: self.embedding = Embedding(input_dim=input_dim, output_dim=emb_dim, mask_zero=True, name='embedding') else: self.embedding = Embedding(input_dim=embeddings.shape[0], output_dim=embeddings.shape[1], mask_zero=True, weights=[embeddings], name='embedding') self.lstm = LSTM(hid_dim, return_sequences=True, name='lstm') self.conv = Conv1D(filters, kernel_size, padding='valid', activation='relu', strides=1) self.pool = GlobalMaxPooling1D() self.fc1 = Dense(hid_dim) self.fc2 = Dense(output_dim, activation='softmax') def build(self): x = self.input embedding = self.embedding(x) lstm = self.lstm(embedding) conv = self.conv(lstm) pool = self.pool(conv) y = self.fc1(pool) y = self.fc2(y) return Model(inputs=x, outputs=y)
まだ回答がついていません
会員登録して回答してみよう