Giter Site home page Giter Site logo

Comments (8)

kboyd avatar kboyd commented on May 30, 2024 1

Thanks for sharing the code, now I do see what's going on. I see the same error on my setup with your code and the following version (with some smaller params so it runs quickly on my laptop) doesn't crash:

run_ = 'Doppelganger_exp_savedmodel'
file_name_model = str(run_)+'.pt'

timelength = 20
sample_len_=1
batch_size_=500
epochs_=1
num_layers_=2
num_units_ = 30
adlr_= 0.8
glr_=0.8
dlr_=0.8

features = np.random.rand(21, 20, 6)
attributes = np.random.rand(21,1)
# Train the model
model = DGAN(DGANConfig(
    max_sequence_len=timelength,
    sample_len=sample_len_,
    batch_size=batch_size_,
    epochs=epochs_, # For real data sets, 100–1000 epochs is typical
    feature_num_layers=num_layers_,
    attribute_discriminator_learning_rate = adlr_,
    feature_num_units = num_units_ ,
    generator_learning_rate = glr_ ,
    discriminator_learning_rate= dlr_,
))

model.train_numpy(
      # run = run_,
      attributes=attributes,
      attribute_types = [OutputType.DISCRETE] * 1,
      features=features,
      feature_types = [OutputType.CONTINUOUS] * (6)
      )
print("model training complete")
model.save(file_name_model)

loaded_model = DGAN.load(file_name=file_name_model)

synthetic_df = loaded_model.generate_numpy(1)

attributes_gen =synthetic_df[0]
features_gen = synthetic_df[1]

What's happening? The key part is that load is a class function that directly returns the DGAN instance. The DGANConfig params are also stored in the saved file, so you don't need to setup the DGAN instance for loading yourself. Just use

loaded_model = DGAN.load(file_name=file_name_model)

Unfortunately, python let's us call class functions on either the class or instances of the class, making it easy to confuse this. In your code, the DGAN instance with the saved model is returned from the load call but isn't stored anywhere and is lost. The loaded_model instance isn't modified from it's original state by the class function, so when you called generate_numpy it was on a model that hadn't been trained yet, just like #144 (comment). I'll look into getting a clearer error message in these situations.

from gretel-synthetics.

AravAct avatar AravAct commented on May 30, 2024

Reopened as error persists. Loading a model and generating new data is not working.

from gretel-synthetics.

santhosh97 avatar santhosh97 commented on May 30, 2024

Hey @AravAct ! Hope you're doing well! Do you mind sharing a snippet of what your input data looks like?

from gretel-synthetics.

AravAct avatar AravAct commented on May 30, 2024

Hi @santhosh97 ,
Thanks for the reply.
Although I cannot share the data directly, I can share the shape of the dataset. We have transformed the data to required format( wide format) for the model.
Shape of the data is (21, 2000, 6)
21 unique timeseries sequences, of length 2000 each and 6 features. We do not have any categorical variables, all are numerical.

from gretel-synthetics.

kboyd avatar kboyd commented on May 30, 2024

We're not able to reproduce that error after loading a model yet to investigate further. @AravAct can you share a minimum chunk of code that produces the error? So the model create, train, save, load, and generate code that leads to the error. I don't expect the exact data is the issue here based on the error, so I'm hoping random data (e.g., np.random.random(21, 6000, 6)) will still reproduce the problem so you can share some code that doesn't rely on your data directly.

from gretel-synthetics.

kboyd avatar kboyd commented on May 30, 2024

The only way I've found to generate the error is to run generate_dataframe (or generate_numpy) immediately after making the DGAN instance, before training:

from gretel_synthetics.timeseries_dgan.config import DGANConfig
from gretel_synthetics.timeseries_dgan.dgan import DGAN
dg = DGAN(DGANConfig(max_sequence_len=2000, sample_len=1))
dg.generate_numpy(n=3)

Output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kendrick/.pyenv/versions/3.8.13/lib/python3.8/site-packages/gretel_synthetics/timeseries_dgan/dgan.py", line 436, in generate_numpy
    self.attribute_noise_func(self.config.batch_size),
AttributeError: 'DGAN' object has no attribute 'attribute_noise_func'

We can definitely provide a clearer error message in this situation. But this seems unrelated to saving and loading a model, so probably not helpful for this bug.

from gretel-synthetics.

AravAct avatar AravAct commented on May 30, 2024

I tried the suggested, adding DGAN instance before loading the model. Below is a reproducible code. Kindly let me know if I am making a mistake or this is something else.

run_ = 'Doppelganger_exp_savedmodel'
file_name_model = str(run_)+'.pt'

timelength = 2000
sample_len_=1
batch_size_=500
epochs_=30
num_layers_=2
num_units_ = 30
adlr_= 0.8
glr_=0.8
dlr_=0.8

features = np.random.rand(21, 2000, 6)
attributes = np.random.rand(21,1)
# Train the model
model = DGAN(DGANConfig(
    max_sequence_len=timelength,
    sample_len=sample_len_,
    batch_size=batch_size_,
    epochs=epochs_, # For real data sets, 100–1000 epochs is typical
     feature_num_layers=num_layers_,
     attribute_discriminator_learning_rate = adlr_,
    feature_num_units = num_units_ ,
    generator_learning_rate = glr_ ,
        discriminator_learning_rate= dlr_,
))

model.train_numpy(
      # run = run_,
      attributes=attributes,
      attribute_types = [OutputType.DISCRETE] * 1,
      features=features,
      feature_types = [OutputType.CONTINUOUS] * (6)
      )
print("model training complete")
model.save(file_name_model)

loaded_model = DGAN(DGANConfig(
    max_sequence_len=timelength,
    sample_len=sample_len_,
    batch_size=batch_size_,
    epochs=epochs_, # For real data sets, 100–1000 epochs is typical
     feature_num_layers=num_layers_,
     attribute_discriminator_learning_rate = adlr_,
    feature_num_units = num_units_ ,
    generator_learning_rate = glr_ ,
        discriminator_learning_rate= dlr_,
))

loaded_model.load(file_name=file_name_model)

synthetic_df = loaded_model.generate_numpy(1)

attributes_gen =synthetic_df[0]
features_gen = synthetic_df[1]

Got the below error

AttributeError                            Traceback (most recent call last)
[<ipython-input-20-02dfe40d3ef9>](https://localhost:8080/#) in <module>
     13 loaded_model.load(file_name=file_name_model)
     14 
---> 15 synthetic_df = loaded_model.generate_numpy(1)
     16 
     17 attributes_gen =synthetic_df[0]

[/usr/local/lib/python3.8/dist-packages/gretel_synthetics/timeseries_dgan/dgan.py](https://localhost:8080/#) in generate_numpy(self, n, attribute_noise, feature_noise)
    434                 internal_data_list.append(
    435                     self._generate(
--> 436                         self.attribute_noise_func(self.config.batch_size),
    437                         self.feature_noise_func(self.config.batch_size),
    438                     )

AttributeError: 'DGAN' object has no attribute 'attribute_noise_func'

from gretel-synthetics.

AravAct avatar AravAct commented on May 30, 2024

loading DGAN directly worked perfectly. I can load the saved model and generate data again. Thanks for the clarification. Closing this.

from gretel-synthetics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.