Skip to content

Commit

Permalink
Fix HDF5 not understanding some files (#313)
Browse files Browse the repository at this point in the history
* Fix bug in HDF5 that would cause an error during training when the
dataset provides energies with shape (Nsamples,) instead of (Nsamples, 1)

* Accommodate for previous behavior
  • Loading branch information
RaulPPelaez committed Apr 4, 2024
1 parent 8b47246 commit 74702da
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion torchmdnet/datasets/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def _preload_data(self):
# Watchout for the 1D case, embed can be shared for all samples
tmp = torch.tensor(np.array(data), dtype=dtype)
if tmp.ndim == 1:
tmp = tmp.unsqueeze(0).expand(size, -1)
if len(tmp) == size:
tmp = tmp.unsqueeze(-1)
else:
tmp = tmp.unsqueeze(0).expand(size, -1)
self.stored_data[field].append(tmp)
self.index.extend(list(zip([i] * size, range(size))))
i += 1
Expand Down

0 comments on commit 74702da

Please sign in to comment.