# Validation Loss reported as null during sweeps?

**URL:** <https://community.wandb.ai/t/validation-loss-reported-as-null-during-sweeps/6190>\
**Category:** W&B Help\
**Created:** [March 25, 2024, 4:16pm UTC](https://community.wandb.ai/t/validation-loss-reported-as-null-during-sweeps/6190 "2024-03-25T16:16:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![katarinaa](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@katarinaa](https://community.wandb.ai/u/katarinaa)\
**Post date:** [March 25, 2024, 4:16pm UTC](https://community.wandb.ai/t/validation-loss-reported-as-null-during-sweeps/6190/1 "2024-03-25T16:16:44Z")

</div>

Hi there,

I’m encountering the issue of val\_loss being reported as null for sweeps, despite val\_loss being successfully reported during individual runs.

This issue happens even after creating a custom callback (which was previously found to be a solution by another user). For example:

> class CustomWandbCallback(Callback):  
> def on\_epoch\_end(self, epoch, logs=None):  
> if logs is not None:  
> wandb.log({“val\_loss”: logs.get(“val\_loss”), “epoch”: epoch})

I wondered if there is a way to fix this? I’ve tried it with and without custom callback with no luck so far:(

Here is my full code (minus the data processing):

> import wandb  
> import pandas as pd  
> import numpy as np  
> import tensorflow as tf  
> import random  
> from sklearn.model\_selection import train\_test\_split  
> from sklearn.preprocessing import StandardScaler  
> from tensorflow.keras.callbacks import Callback, ModelCheckpoint
> 
> # Custom callback
> 
> class CustomWandbCallback(Callback):  
> def on\_epoch\_end(self, epoch, logs=None):  
> if logs is not None:  
> # Log ‘val\_loss’ and any other metrics you’re interested in  
> # You can add more metrics to log here as needed  
> wandb.log({“val\_loss”: logs.get(“val\_loss”), “epoch”: epoch})
> 
> … data processing…
> 
> # Start a run
> 
> wandb.init(project=“Neural Network 1”,  
> config={  
> “layer\_1”: 128,  
> “activation\_1”: “relu”,  
> “dropout”: random.uniform(0.01, 0.50),  
> “layer\_2”: 64,  
> “activation\_2”: “relu”,  
> “layer\_output”: y.shape[1],  
> “optimizer”: “adam”,  
> “loss”: “mean\_squared\_error”,  
> “epoch”: 30,  
> “batch\_size”: 32  
> })
> 
> config = wandb.config
> 
> print(‘Project configured successfully’)
> 
> # Build the model
> 
> model = tf.keras.models.Sequential([  
> tf.keras.layers.Dense(config.layer\_1, activation=config.activation\_1, input\_shape=(X\_train.shape[1],)),  
> tf.keras.layers.Dropout(config.dropout),  
> tf.keras.layers.Dense(config.layer\_2, activation=config.activation\_2),  
> tf.keras.layers.Dense(config.layer\_output)  
> ])
> 
> model.compile(optimizer=config.optimizer, loss=config.loss)
> 
> print(‘Model built successfully’)
> 
> model\_checkpoint = ModelCheckpoint(  
> filepath=“models/best\_model.h5”, # Path where to save the model  
> save\_best\_only=True, # Save only the best model  
> monitor=‘val\_loss’, # Criterion to monitor  
> mode=‘min’, # The smaller the monitored quantity, the better the model  
> verbose=1 # Log when the best model is updated  
> )
> 
> history = model.fit(x=X\_train, y=y\_train,  
> epochs=config.epoch,  
> batch\_size=config.batch\_size,  
> validation\_data=(X\_test, y\_test),  
> callbacks=[  
> CustomWandbCallback(),  
> model\_checkpoint # Use the modified ModelCheckpoint  
> ])
> 
> wandb.finish()  
> print(‘Finished’)

---

<div class="post-metadata">

**Author:** ![uma-wandb](https://avatars.discourse-cdn.com/v4/letter/u/b77776/32.png) [@uma-wandb](https://community.wandb.ai/u/uma-wandb)\
**Post date:** [April 1, 2024, 3:18am UTC](https://community.wandb.ai/t/validation-loss-reported-as-null-during-sweeps/6190/2 "2024-04-01T03:18:47Z")

</div>

hey @katarinaa - would it be possible to send over a short snippet for how you’re setting up your sweep? (how you’re initializing your agent, defining your training function with the above snippet, etc)

---

<div class="post-metadata">

**Author:** ![uma-wandb](https://avatars.discourse-cdn.com/v4/letter/u/b77776/32.png) [@uma-wandb](https://community.wandb.ai/u/uma-wandb)\
**Post date:** [April 3, 2024, 10:14pm UTC](https://community.wandb.ai/t/validation-loss-reported-as-null-during-sweeps/6190/3 "2024-04-03T22:14:11Z")

</div>

Hi Katarina, since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, feel free to write back in

---

<div class="post-metadata">

**Author:** ![katarinaa](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@katarinaa](https://community.wandb.ai/u/katarinaa)\
**Post date:** [April 4, 2024, 2:17pm UTC](https://community.wandb.ai/t/validation-loss-reported-as-null-during-sweeps/6190/4 "2024-04-04T14:17:52Z")

</div>

Sure, here is the snippet I am using to initialise the sweep:

> module load bear-apps/2021b/live  
> module load Python/3.9.6-GCCcore-11.2.0  
> python --version  
> python /rds/homes/k/kbp045/PYTHON/waste\_data/Neural\ Network\ 1/train.py --activation
> 
> wandb agent es-and-d/“Neural Network 1”/[insert sweep ID here]
