Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sujanme25 opened this issue Jun 19, 2020 · 3 comments

Comments

@sujanme25
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

Working in colab but not in jupyter notebook.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants