I thought I had this programming assignment correct, but when I run the test I get the errors below.
I am wondering if it is is because I am adding the binary classification layers incorrectly. I have tried a few different methods, but currently I am trying to use:
x = tfl.GlobalAveragePooling2D()(base_model.output)
Is this the correct way to add the new layers to the base model we loaded without the top layers?
RuntimeError Traceback (most recent call last)
in
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)
in alpaca_model(image_shape, data_augmentation)
48
49 # use a prediction layer with one neuron (as a binary classifier only needs one)
—> 50 outputs = base_model.evaluate(inputs, x)
51
52 ### END CODE HERE
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
106 def _method_wrapper(self, *args, **kwargs):
107 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
→ 108 return method(self, *args, **kwargs)
109
110 # Running inside run_distribute_coordinator
already.
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in evaluate(self, x, y, batch_size, verbose, sample_weight, steps, callbacks, max_queue_size, workers, use_multiprocessing, return_dict)
1333 _keras_api_gauge.get_cell(‘evaluate’).set(True)
1334 version_utils.disallow_legacy_graph(‘Model’, ‘evaluate’)
→ 1335 self._assert_compile_was_called()
1336 self._check_call_args(‘evaluate’)
1337 _disallow_inside_tf_function(‘evaluate’)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _assert_compile_was_called(self)
2567 # (i.e. whether the model is built and its inputs/outputs are set).
2568 if not self._is_compiled:
→ 2569 raise RuntimeError('You must compile your model before ’
2570 'training/testing. ’
2571 ‘Use model.compile(optimizer, loss)
.’)
RuntimeError: You must compile your model before training/testing. Use model.compile(optimizer, loss)
.