Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def download():
vol = hub.load(name='imagenet/image:val')[400:600]
a = (vol.mean(axis=(1,2,3)) == 0).sum()
print(vol.mean(axis=(1,2,3)) == 0)
def test_public_access_no_creds():
x = hub.load('imagenet')
assert x[0].mean() == 1
import hub
import numpy as np
def download():
vol = hub.load(name='imagenet/image:val')[400:600]
a = (vol.mean(axis=(1,2,3)) == 0).sum()
print(vol.mean(axis=(1,2,3)) == 0)
mnist = hub.array((50000, 28, 28, 1), name="jason/mnist:v2", dtype='float32')
mnist[0, :] = np.random.random((1, 28, 28, 1)).astype('float32')
print(mnist[0,0,0,0])
# TODO load
mnist = hub.load(name='jason/mnist:v1')
print(mnist[0].shape)
print(mnist[0,0,0,0])
def test_aws_wo_hub_creds():
os.system('mv ~/.hub ~/.hub_arxiv')
import hub
x = hub.array((100, 100, 100), 'image/test:smth', dtype='uint8')
print(x.shape)
os.system('mv ~/.hub_arxiv ~/.hub')
def test_wo_aws_or_hub_creds():
os.system('mv ~/.aws ~/.aws_arxiv')
os.system('mv ~/.hub ~/.hub_arxiv')
try:
import hub
x = hub.array((100, 100, 100), 'image/test:smth', dtype='uint8')
print(x.shape)
except Exception as err:
print('pass', err)
pass
os.system('mv ~/.hub_arxiv ~/.hub')
os.system('mv ~/.aws_arxiv ~/.aws')
import hub
import numpy as np
x = hub.array((10,10,10,10), name="davit/example:1", dtype='uint8')
#[0] = np.zeros((1,10,10,10), dtype='uint8') # need to assign
x[1,0,0,0] = 1
import hub
import numpy as np
shape = (10, 10, 10)
x = hub.array(shape, name="test/example:1", dtype='uint8')
x[10]
def test_pytorch():
# Create arrays
datahub = hub.fs("./data/cache").connect()
images = datahub.array(
name="test/dataloaders/images3",
shape=(100, 100, 100),
chunk=(1, 100, 100),
dtype="uint8",
)
labels = datahub.array(
name="test/dataloaders/labels3", shape=(100, 1), chunk=(100, 1), dtype="uint8"
)
# Create dataset
ds = datahub.dataset(
name="test/loaders/dataset2", components={"images": images, "labels": labels}
)
# Transform to Pytorch
train_dataset = ds.to_pytorch()
# Create data loader
def test_broadcasting():
print("- Broadcasting")
datahub = hub.fs("./data/cache").connect()
shape = (100, 100, 100)
chunk = (50, 50, 50)
x = datahub.array(name="test/example:3", shape=shape, chunk=chunk, dtype="uint8")
x[0, 0, 0] = 11
assert x[0, 0, 0] == 11
x[0] = 10
assert x[0].mean() == 10
x[1] = np.ones((100, 100), dtype="uint8")
assert x[1].mean() == 1
x[3, 90, :] = np.ones((1, 1, 100), dtype="uint8")
assert x[3, 90].mean() == 1
print("passed")
def test_dataset():
datahub = hub.fs("./data/cache").connect()
x = datahub.array(name='test/example:input', shape = (100, 25, 25), chunk=(20, 5, 5), dtype='uint8')
y = datahub.array(name='test/example:label', shape = (100, 4), chunk = (20, 2), dtype='uint8')
ds = datahub.dataset(components={
'input': x,
'label': y
}, name='test/dataset:train3')
assert ds[0]['input'].shape == (25, 25)
assert ds['input'].shape[0] == 100 # return single array
assert ds['label', 0].mean() == 0 # equivalent ds['train'][0]