grudloff / stock_market_GAN

Reproduction of code described in the paper "Stock Market Prediction Based on Generative Adversarial Network" by Kang Zhang et al.
25 stars 8 forks source link

TypeError: compile() missing 1 required positional argument: 'optimizer' #1

Open sujanme25 opened 4 years ago

sujanme25 commented 4 years ago

generator = make_generator_model() Giving error please check as below.


TypeError Traceback (most recent call last)

in ----> 1 generator = make_generator_model() in make_generator_model() 27 model = Model(inputs = inputs, outputs = output) 28 #model.compile(loss=generator_loss) ---> 29 model.compile(loss=None, metrics = [mse , mae, mape, rmse, ar]) 30 #model.compile(loss=None, metrics = [mse , mae, mape, rmse]) 31 model.summary() D:\Anaconda\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, **kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, *args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access TypeError: compile() missing 1 required positional argument: 'optimizer'
grudloff commented 4 years ago

That is odd, we use a custom training loop following this tensorflow example. The .compile() call is just to add the metrics, as you can see it's called with loss=None so it is very odd that it is requiring an optimizer. Maybe you are using an older version of tensorflow, we ran these notebooks on google colab, you can try to train there, or emulate that environment.

sujanme25 commented 4 years ago

I have used tensorflow 2.1.0 now i am getting RuntimeError: You must compile your model before training/testing. Use model.compile(optimizer, loss).


RuntimeError Traceback (most recent call last)

in 33 discriminator=discriminator) 34 ---> 35 history, history_val = train(data_gen_train, data_gen_test, EPOCHS) 36 37 plot_history(history, history_val) in train(dataset, dataset_val, epochs) 18 19 #cur_gen_loss = generator.evaluate(dataset,verbose=False) ---> 20 cur_gen_metrics = generator.evaluate(dataset,verbose=False)[1:] 21 #cur_dis_loss = discriminator.evaluate(dataset,verbose=False) 22 D:\Anaconda\envs\tensorflow_env\lib\site-packages\tensorflow_core\python\keras\engine\training.py in evaluate(self, x, y, batch_size, verbose, sample_weight, steps, callbacks, max_queue_size, workers, use_multiprocessing) 913 """ 914 _keras_api_gauge.get_cell('evaluate').set(True) --> 915 self._assert_compile_was_called() 916 self._check_call_args('evaluate') 917 D:\Anaconda\envs\tensorflow_env\lib\site-packages\tensorflow_core\python\keras\engine\training.py in _assert_compile_was_called(self) 2826 # (i.e. whether the model is built and its inputs/outputs are set). 2827 if not self.optimizer: -> 2828 raise RuntimeError('You must compile your model before ' 2829 'training/testing. ' 2830 'Use `model.compile(optimizer, loss)`.') RuntimeError: You must compile your model before training/testing. Use `model.compile(optimizer, loss)`.
sujanme25 commented 4 years ago

Working in colab but not in jupyter notebook. Thanks