pesser / edflow

Reduce boilerplate code for your ML projects. TensorFlow and PyTorch.
https://edflow.readthedocs.io/
MIT License
24 stars 13 forks source link

unable to dump config when using tfe with keras model #240

Closed theRealSuperMario closed 4 years ago

theRealSuperMario commented 4 years ago

When adding the config to a model that inherits from tf.keras.Model, the config cannot be dumped. It looks like keras changes lists within the config to a ListWrapper object, which are not reduceably by yaml.dump

To Reproduce

"""exp.py"""
import tensorflow as tf

tf.enable_eager_execution()

from tensorflow import keras as tfk
import numpy as np
from edflow import TemplateIterator, get_logger

class Model(tfk.Model):
    def __init__(self, config):
        super().__init__()
        self.config = config

    def call(self, x1, x2):
        pass

class Iterator(TemplateIterator):
    def __init__(self, *args, **kwargs):
        super(Iterator, self).__init__(*args, **kwargs)
dataset: edflow.datasets.fashionmnist.FashionMNIST
validation_dataset: edflow.datasets.fashionmnist.FashionMNIST
model: exp.Model
iterator: exp.Iterator

batch_size: 4
size: 128

num_epochs: 10

foo:
  bar: [1, 2]

run edflow -b config.yaml -t -n foo -d gives

NotImplementedError: object proxy must define __reduce_ex__()

Expected behavior I expect the config to be dumped

Additional context Workaround is to simply not do self.config = config and save everything you need in a field in the model.

pesser commented 4 years ago

please provide a plan of action: There is not much edflow can do about the way Keras handles attributes, so imho the best we can do is mention it in the faq. Can you add an entry for it and then close this issue?

theRealSuperMario commented 4 years ago

Adding it to FAQ is a good idea.

theRealSuperMario commented 4 years ago

documented in #252