You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
Hi,
I am using CRF from keras_contrib,but I get this error " AttributeError: 'Tensor' object has no attribute '_keras_history'", when model.fit() is called.
Any help would be highly appreciated
This is my import
import numpy as np
import os
import tensorflow as tf
from scipy.io import loadmat
from tensorflow import keras
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Dense,Dropout,TimeDistributed,Bidirectional,LSTM,Input
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.models import Sequential
from tensorflow.keras.callbacks import ModelCheckpoint
from keras_contrib.layers.crf import CRF
from keras_contrib.losses import crf_loss
from keras_contrib.metrics import crf_viterbi_accuracy
from tensorflow.keras import Model
This my partial code
model = Sequential()
model.add(Dense(4,activation='softmax'))
model.add(CRF(4))
model.compile(optimizer='RMsprop',
loss=crf_loss,
metrics=[crf_viterbi_accuracy])
Traceback (most recent call last):
File "D:/CRF+LSTM/test1.py", line 426, in
Linear_crf(train_data,train_label,test_data,test_label)
File "D:/CRF+LSTM/test1.py", line 420, in Linear_crf
validation_split=0.2, callbacks=[cp_callback])
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1183, in fit
tmp_logs = self.train_function(iterator)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 889, in call
result = self._call(*args, **kwds)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 933, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 764, in _initialize
*args, **kwds))
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\function.py", line 3050, in _get_concrete_function_internal_garbage_collected
graph_function, _ = self._maybe_define_function(args, kwargs)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\function.py", line 3444, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\function.py", line 3289, in _create_graph_function
capture_by_value=self._capture_by_value),
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\framework\func_graph.py", line 999, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 672, in wrapped_fn
out = weak_wrapped_fn().wrapped(*args, **kwds)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\framework\func_graph.py", line 986, in wrapper
raise e.ag_error_metadata.to_exception(e)
AttributeError: in user code:
tensorflow-gpu==2.2.0
kears==2.3.1
keras_contrib=2.0.8
CUDA=10.1
cudnn=7.6.5
if I use from kears.layers import *,it not can use my GPU accelerate my code, use my CPU,but i use from tensorflow.keras.layers import * , it can use GPU accelerate, but have a error:
The added layer must be an instance of class Layer. Found: <keras_contrib.layers.crf.CRF object at 0x12bfa4550>
The text was updated successfully, but these errors were encountered:
Hi,
I am using CRF from keras_contrib,but I get this error " AttributeError: 'Tensor' object has no attribute '_keras_history'", when model.fit() is called.
Any help would be highly appreciated
This is my import
import numpy as np
import os
import tensorflow as tf
from scipy.io import loadmat
from tensorflow import keras
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Dense,Dropout,TimeDistributed,Bidirectional,LSTM,Input
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.models import Sequential
from tensorflow.keras.callbacks import ModelCheckpoint
from keras_contrib.layers.crf import CRF
from keras_contrib.losses import crf_loss
from keras_contrib.metrics import crf_viterbi_accuracy
from tensorflow.keras import Model
This my partial code
model = Sequential()
model.add(Dense(4,activation='softmax'))
model.add(CRF(4))
model.compile(optimizer='RMsprop',
loss=crf_loss,
metrics=[crf_viterbi_accuracy])
Traceback (most recent call last):
File "D:/CRF+LSTM/test1.py", line 426, in
Linear_crf(train_data,train_label,test_data,test_label)
File "D:/CRF+LSTM/test1.py", line 420, in Linear_crf
validation_split=0.2, callbacks=[cp_callback])
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1183, in fit
tmp_logs = self.train_function(iterator)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 889, in call
result = self._call(*args, **kwds)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 933, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 764, in _initialize
*args, **kwds))
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\function.py", line 3050, in _get_concrete_function_internal_garbage_collected
graph_function, _ = self._maybe_define_function(args, kwargs)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\function.py", line 3444, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\function.py", line 3289, in _create_graph_function
capture_by_value=self._capture_by_value),
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\framework\func_graph.py", line 999, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\eager\def_function.py", line 672, in wrapped_fn
out = weak_wrapped_fn().wrapped(*args, **kwds)
File "D:\machine_learning\Anaconda_3\envs\cc\lib\site-packages\tensorflow\python\framework\func_graph.py", line 986, in wrapper
raise e.ag_error_metadata.to_exception(e)
AttributeError: in user code:
tensorflow-gpu==2.2.0
kears==2.3.1
keras_contrib=2.0.8
CUDA=10.1
cudnn=7.6.5
if I use from kears.layers import *,it not can use my GPU accelerate my code, use my CPU,but i use from tensorflow.keras.layers import * , it can use GPU accelerate, but have a error:
The added layer must be an instance of class Layer. Found: <keras_contrib.layers.crf.CRF object at 0x12bfa4550>
The text was updated successfully, but these errors were encountered: