Skip to content

Commit

Permalink
Update all files Issue: activeloopai#205
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselmoo committed Nov 17, 2020
1 parent 63612dd commit b964055
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 35 deletions.
3 changes: 2 additions & 1 deletion examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from hub import dev_mode


def main():
# Tag is set {Username}/{Dataset}
tag = "davitb/basic11"
Expand All @@ -16,7 +17,6 @@ def main():
},
)


# Upload Data
ds["image"][:] = np.ones((4, 512, 512))
ds["label"][:] = np.ones((4, 512, 512))
Expand All @@ -26,5 +26,6 @@ def main():
ds = Dataset(tag)
print(ds["image"][0].compute())


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion examples/big_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def main():


if __name__ == "__main__":
main()
main()
19 changes: 15 additions & 4 deletions examples/eurosat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import hub
import torch

if __name__ == "__main__":

def main():
ds = hub.Dataset("eurosat/eurosat-rgb")

# 26000 samples in dataset, accessing values
print(ds["image"][10].numpy())
print(ds["label", 15].numpy()) # alternate way to access, by specifying both key and sample number at once
print(
ds["label", 15].numpy()
) # alternate way to access, by specifying both key and sample number at once
print(ds["filename", 20:22].numpy()) # accessing multiple elements at once

# Splitting into train and test sets
Expand All @@ -31,11 +34,19 @@
train_loader = torch.utils.data.DataLoader(train_pt_ds, batch_size=2)

for batch in train_loader:
print(batch["label"], batch["image"]) # pytorch tensors don't support text labels such as filename
print(
batch["label"], batch["image"]
) # pytorch tensors don't support text labels such as filename
break

test_pt_ds = test_ds.to_pytorch()
test_loader = torch.utils.data.DataLoader(test_pt_ds, batch_size=2)
for batch in test_loader:
print(batch["label"], batch["image"]) # pytorch tensors don't support text labels such as filename
print(
batch["label"], batch["image"]
) # pytorch tensors don't support text labels such as filename
break


if __name__ == "__main__":
main()
5 changes: 2 additions & 3 deletions examples/large_dataset_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def create_large_dataset():
for i in range(len(ds) // 10):
ds["image", i * 10 : i * 10 + 10] = i * array
ds.commit()

ds = hub.Dataset("./data/examples/large_dataset_build")
print(ds.keys, ds["image"].shape, ds["image"].dtype)


# Read the dataset
with hub.Dataset("./data/examples/large_dataset_build") as ds:
Expand All @@ -34,4 +33,4 @@ def create_large_dataset():


if __name__ == "__main__":
create_large_dataset()
create_large_dataset()
34 changes: 20 additions & 14 deletions examples/load_tf.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from hub import Dataset, features

# Create dataset
ds = Dataset(
"./data/example/pytorch",
shape=(64,),
schema={
"image": features.Tensor((512, 512), dtype="float"),
"label": features.Tensor((512, 512), dtype="float"),
},
)

# tansform into Tensorflow dataset
ds = ds.to_tensorflow().batch(8)
def main():
# Create dataset
ds = Dataset(
"./data/example/pytorch",
shape=(64,),
schema={
"image": features.Tensor((512, 512), dtype="float"),
"label": features.Tensor((512, 512), dtype="float"),
},
)

# Iterate over the data
for batch in ds:
print(batch["image"], batch["label"])
# tansform into Tensorflow dataset
ds = ds.to_tensorflow().batch(8)

# Iterate over the data
for batch in ds:
print(batch["image"], batch["label"])


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion examples/mnist_upload_speed_bechmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def main():


if __name__ == "__main__":
main()
main()
28 changes: 17 additions & 11 deletions examples/new_api_intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
from hub import Dataset
from hub.features import ClassLabel, Image

schema = {
"image": Image((28, 28)),
"label": ClassLabel(num_classes=10),
}

ds = Dataset("./data/examples/new_api_intro", shape=(1000,), schema=schema)
def main():
schema = {
"image": Image((28, 28)),
"label": ClassLabel(num_classes=10),
}

for i in range(len(ds)):
ds["image", i] = np.ones((28, 28), dtype="uint8")
ds["label", i] = 3
ds = Dataset("./data/examples/new_api_intro", shape=(1000,), schema=schema)

print(ds["image", 5].numpy())
print(ds["label", 100:110].numpy())
ds.commit()
for i in range(len(ds)):
ds["image", i] = np.ones((28, 28), dtype="uint8")
ds["label", i] = 3

print(ds["image", 5].numpy())
print(ds["label", 100:110].numpy())
ds.commit()


if __name__ == "__main__":
main()

0 comments on commit b964055

Please sign in to comment.