cjiang2 / VDCNN

Implementation of Very Deep Convolutional Neural Network for Text Classification
171 stars 41 forks source link

Cannot save model #18

Closed Yocodeyo closed 3 years ago

Yocodeyo commented 3 years ago

Hi, your code is really an interesting implementation. However, I faced problems when saving the model when running model.to_json() in train.py The error message looks like:

File "train.py", line 71, in train model_json = model.to_json() File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py", line 2264, in to_json model_config = self._updated_config() File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py", line 2221, in _updated_config config = self.get_config() File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/functional.py", line 598, in get_config return copy.deepcopy(get_network_config(self)) File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/functional.py", line 1278, in get_network_config layer_config = serialize_layer_fn(layer) File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 250, in serialize_keras_object raise e File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 245, in serialize_keras_object config = instance.get_config() File "/home/mzli/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 676, in get_config raise NotImplementedError('Layer %s has arguments in __init__ and ' NotImplementedError: Layer KMaxPooling has arguments in __init__ and therefore must override get_config.

May I get some advice on this issue? Many thanks!!

cjiang2 commented 3 years ago

Hello,

Update:

Using Tensorflow-Datasets' AG’s News loader. You will need to implement tfds objects for other datasets though.

(Personally I suggest to switch to PyTorch. Currently eager implementation of VDCNN makes much more sense and it's way easier to be reimplemented in PyTorch)

Issue closed at the moment.

This project was done 3 years ago when keras was still separated from Tensorflow + Tensorflow was using static graphs. Things have been extremely different nowadays.

You will need to refer to the newer Tensorflow tutorial and rewrite the interface for training and evaluation completely. I'm not sure if I have time to do it these days.

I have updated the VDCNN model codebase against Tensorflow 2 though, you are welcome to test it.