Comments (8)
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.
Reopened as error persists. Loading a model and generating new data is not working.
from gretel-synthetics.
Hey @AravAct ! Hope you're doing well! Do you mind sharing a snippet of what your input data looks like?
from gretel-synthetics.
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.
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.
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.
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.
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)
- [BUG] Incompatability with package dependence HOT 2
- timeseries_dgan.ipynb example - error from train_numpy HOT 2
- TypeError: __init__() got an unexpected keyword argument 'prefetch_factor' HOT 1
- Poor training results HOT 6
- TooManyInvalidError: Maximum number of invalid lines reached! HOT 3
- [BUG] train_numpy() got multiple values for argument 'feature_types' - dgan HOT 4
- [FR] Generation based on given attributes HOT 2
- [FR / BUG] HOT 2
- Bug HOT 5
- Sample_len Value HOT 2
- Results about DGAN
- About DoppelGANger training results HOT 1
- [BUG]: Outdated category_encoders HOT 3
- List index out of range HOT 4
- ValueError: multiprocessing_context option should specify a valid start method in ['spawn'], but got multiprocessing_context='fork'[FR / BUG] HOT 1
- [BUG] example notebook error HOT 3
- Marketoptiontend-analysis
- DGAN for ECG dataset HOT 3
- Logging the Performance of Time series DGAN,
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gretel-synthetics.