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): ...@@ -1359,18 +1359,16 @@ class Data(numpy.ndarray):
def __new__(cls, urls, metadata, in_memory=True, data=None): def __new__(cls, urls, metadata, in_memory=True, data=None):
urls = numpy.asarray(urls) urls = numpy.asarray(urls)
if in_memory: if in_memory:
if data is not None and urls.shape == data.shape[:-2]: if data is None or urls.shape != data.shape[:-2]:
input_data = data
else:
# Create array as stack of images # Create array as stack of images
input_data = [] input_data = []
for url in urls.flatten(): for url in urls.flatten():
input_data += [utils.get_data(url)] input_data.append(utils.get_data(url))
input_data = numpy.asarray(input_data) data = numpy.asarray(input_data)
shape = list(urls.shape) shape = list(urls.shape)
shape.append(input_data.shape[-2]) shape.append(data.shape[-2])
shape.append(input_data.shape[-1]) shape.append(data.shape[-1])
obj = input_data.reshape(shape).view(cls) obj = data.reshape(shape).view(cls)
else: else:
# Access image one at a time using url # Access image one at a time using url
obj = super(Data, cls).__new__(cls, urls.shape) obj = super(Data, cls).__new__(cls, urls.shape)
......
Supports Markdown
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