Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shapes3D dataset is not included in the data download script #18

Open
alexrakowski opened this issue Nov 15, 2019 · 5 comments
Open

Shapes3D dataset is not included in the data download script #18

alexrakowski opened this issue Nov 15, 2019 · 5 comments

Comments

@alexrakowski
Copy link

Also the .npz file listed in


is not to be found anywhere on the web.

@besterma
Copy link

Hi,
You can find the Shapes3D dataset on Github linking to here. Save it in your DISENTANGLEMENT_LIB_DATA folder in folder 3dshapes.

To use it in disentanglement_lib, change

SHAPES3D_PATH = os.path.join(
os.environ.get("DISENTANGLEMENT_LIB_DATA", "."), "3dshapes",
"look-at-object-room_floor-hueXwall-hueXobj-"
"hueXobj-sizeXobj-shapeXview-azi.npz"
)

to

SHAPES3D_PATH = os.path.join(
    os.environ.get("DISENTANGLEMENT_LIB_DATA", "."), "3dshapes", "3dshapes.h5"
)

and

with tf.gfile.GFile(SHAPES3D_PATH, "rb") as f:
# Data was saved originally using python2, so we need to set the encoding.
data = np.load(f, encoding="latin1")
images = data["images"]
labels = data["labels"]
n_samples = np.prod(images.shape[0:6])

to

with h5py.File(SHAPES3D_PATH, 'r') as dataset:
      images = dataset['images'][()]
      labels = dataset['labels'][()]
n_samples = images.shape[0]

Hope that helps.

@alexrakowski
Copy link
Author

It helps, I have found the .h5 file myself, but it would be convenient if the appropriate changes to the code were included in the repository.
I am using this as a package and would like to avoid editing the code (or creating a fork just for this purpose).

@neeland
Copy link

neeland commented May 31, 2021

Convert h5py to npz using the following in a python file:

import h5py
import numpy as np


hf = h5py.File('./3dshapes.h5', 'r')
print(hf)
values_to_save = {"images": hf['images'], "labels": hf['labels']}
np.savez('look-at-object-room_floor-hueXwall-hueXobj-hueXobj-sizeXobj-shapeXview-azi.nzp', **values_to_save)

@noahcao
Copy link

noahcao commented Nov 12, 2021

@neonkitchen I think you should resize the saved image array. Because the default implementation of Shapes3D dataset requires to reshape the loaded image when using.

@Adamdad
Copy link

Adamdad commented Nov 14, 2021

`import h5py
import numpy as np

hf = h5py.File('./3dshapes.h5', 'r')
print(hf)
values_to_save = {"images": hf['images'].reshape([10,10,10,8,4,15,64,64,3]), "labels": hf['labels']}
np.savez('look-at-object-room_floor-hueXwall-hueXobj-hueXobj-sizeXobj-shapeXview-azi.nzp', **values_to_save)
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants