eisen-ai / eisen-core

Core functionality of Eisen
MIT License
41 stars 10 forks source link

convert_output_dict_to_cpu removes metrics if they return scalars #31

Open dasturge opened 4 years ago

dasturge commented 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):
    ....