Commit 7c5f9793 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[core][dataset][data] Improve code

parent 66dc02cd
......@@ -1359,18 +1359,16 @@ class Data(numpy.ndarray):
def __new__(cls, urls, metadata, in_memory=True, data=None):
urls = numpy.asarray(urls)
if in_memory:
if data is not None and urls.shape == data.shape[:-2]:
input_data = data
else:
if data is None or urls.shape != data.shape[:-2]:
# Create array as stack of images
input_data = []
for url in urls.flatten():
input_data += [utils.get_data(url)]
input_data = numpy.asarray(input_data)
input_data.append(utils.get_data(url))
data = numpy.asarray(input_data)
shape = list(urls.shape)
shape.append(input_data.shape[-2])
shape.append(input_data.shape[-1])
obj = input_data.reshape(shape).view(cls)
shape.append(data.shape[-2])
shape.append(data.shape[-1])
obj = data.reshape(shape).view(cls)
else:
# Access image one at a time using url
obj = super(Data, cls).__new__(cls, urls.shape)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment