As beginner, I am following the tutorials from the tensorflow website. In the regression part, I am getting the following error
command: size_histories['Tiny'] = compile_and_fit(tiny_model, 'sizes/Tiny')
Error:
NameError: name 'logdir' is not defined
I will really appreciate any help.
The complete error message is here:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-29-6b42ade0df41> in <module>
----> 1 size_histories['Small'] = compile_and_fit(small_model, 'sizes/Small')
<ipython-input-20-37c172377a6c> in compile_and_fit(model, name, optimizer, max_epochs)
16 epochs=max_epochs,
17 validation_data=validate_ds,
---> 18 callbacks=get_callbacks(name),
19 verbose=0)
20 return history
<ipython-input-19-1fd695b661fd> in get_callbacks(name)
3 tfdocs.modeling.EpochDots(),
4 tf.keras.callbacks.EarlyStopping(monitor='val_binary_crossentropy', patience=200),
----> 5 tf.keras.callbacks.TensorBoard(logdir/name),
6 ]
NameError: name 'logdir' is not defined
So by googling "compile_and_fit" "tiny_model" logdir
I found that the tutorial you're following must behttps://www.tensorflow.org/tutorials/keras/overfit_and_underfit
As the backtrace tells you, compile_and_fit()
calls get_callbacks()
, which in turn uses the variable logdir
. logdir
is not passed directly to get_callbacks()
as a parameter, nor is it defined anywhere inside the function. So, get_callbacks()
gets to that line, sees the name logdir
, fails to find anything of that name in its local variables, and therefore tries to access a global variable of that name instead. But Python is complaining that nothing of that name exists at all, not even a global variable—so I guess you must have skipped the earlier part of the tutorial, where you would have set up that global variable:
logdir = pathlib.Path(tempfile.mkdtemp())/"tensorboard_logs"
shutil.rmtree(logdir, ignore_errors=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.