Open dasturge opened 4 years ago
the last line assumes that if the value is not a torch tensor or numpy array it should be removed, so it silently eliminates any scalar values returned from losses, metrics, or inputs/outputs
if isinstance(output_dict[typ][i][key], torch.Tensor): output_dict[typ][i][key] = ( output_dict[typ][i][key].cpu().data.numpy() ) elif isinstance(output_dict[typ][i][key], np.ndarray): pass else: output_dict[typ][i].pop(key, None)
the python "numbers" package can be used to check if a value is a number of any kind.
import numbers if isinstance(x, numbers.Number): ....
the last line assumes that if the value is not a torch tensor or numpy array it should be removed, so it silently eliminates any scalar values returned from losses, metrics, or inputs/outputs
the python "numbers" package can be used to check if a value is a number of any kind.