'TensorBoard ValueError: Expected scalar shape, saw shape: (1,)
When I use the callback function TensorBoard as the following:
skip_training = False
tensorboad_cb = TensorBoard('logs')
def train_model(model, callbacks_list):
'''
Input:
Model and callback list,
Return:
Model with best-checkpoint weights.
'''
## TYPE YOUR CODE for task 10 here:
#history = model.fit(X_tr, y_tr, batch_size=4096, epochs=20, verbose=1, validation_data=(X_va, y_va), callbacks=[callbacks_list])
if not skip_training:
history = model.fit(X_tr, y_tr, batch_size=4096, epochs=1, verbose=1, callbacks=[tensorboad_cb])
model.save(checkpoint_name)
else:
model = load_model(checkpoint_name)
return model
model = train_model(model, callbacks_list)
I get this error:
287/287 [==============================] - 180s 626ms/step - loss: 0.1103 - f1_score: 0.6010 - acc: 0.9565 --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () 17 return model 18 ---> 19 model = train_model(model, callbacks_list) 20 21 #history = model.fit(train_data, epochs=15, validation_data=valid_data, validation_steps=50, callbacks=[checkpoint_callback])
9 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/check_ops.py in assert_scalar(tensor, name, message) 2282 if context.executing_eagerly(): 2283 raise ValueError('%sExpected scalar shape, saw shape: %s.' -> 2284 % (message or '', shape,)) 2285 else: 2286 raise ValueError('%sExpected scalar shape for %s, saw shape: %s.'
ValueError: Expected scalar shape, saw shape: (1,).
Solution 1:[1]
I have same issue on tensorflow 2.6.2, but on tensorflow 2.4.1 it works well.
finally, I fixed it by comment the code:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Crazy_LittleBoy |
