Data_Block_API to read numpy Arrays

(Rajdeep Das) #1

Hi All !

Data_block_API taught in courses reads images from the folders or from the path mentioned. Is there any way I can use datablock API, to wrap a numpy array of size= (mdim1dim2); m=training samples. as a torch tensor ?

(Phuc Le) #2

Not sure about the Data_block_API or what you want to achieve with it, but to convert numpy array to Tensor just use torch.from_numpy(my_arr) . The resulting Tensor will share the same memory with the numpy array, so no duplication even happen.


I’m not sure if you are looking for something like this, but i managed to load image data previously saved as Tensor (could be numpy array / txt)

class CustomImageItemList(ImageItemList):
    def open(self, fn):
        return Image(torch.load(fn))

lst = CustomImageItemList.from_folder(Path('clean_pt'), '.pt')

How to convert pixel value numpy array of images into ImageDataBunch object
(Stefano) #4

This may help:

Subclassing let library to deal with torch.

(Rajdeep Das) #5

Thanks All. I am currently following this link, that does this in an explicit manner.