Create_func removed from data_block

I noticed that the create_func argument was removed from the datablock. Is there another way to do this now through another method? Would there be an example of this?

from the changes.md in the repo for version 1.0.28 this is listed as breaking change:

  • create_func is removed in the data API; subclass and change the get method instead (in vision, you can subclass the open method if you want to change how the images are opened).

Just remembered that I read that a few days ago, have not tried myself but maybe it points you in the right direction…

I have found it helpful to check this document often lately, lots of things breaking… :wink:

3 Likes

That’s exactly what I needed. My only regret is that I have just one like to give.

1 Like

In case anybody else has this issue, here is what my code looks like to fix it:

Here is the create_func that was being used (This is from Radek’s Quickdraw Starter):

def create_func(path):
    with open(path) as f: j = json.load(f)
    drawing = list2drawing(j['drawing'], size=sz)
    tensor = drawing2tensor(drawing)
    return Image(tensor.div_(255))

What I had to use is:

class JSONImageItemList(ImageItemList):
    def open(self,fn):
        with io.open(fn) as f: j = json.load(f)
        drawing = list2drawing(j['drawing'], size=sz)
        tensor = drawing2tensor(drawing)
        return Image(tensor.div_(255))

So I had to import io so I could do io.open, but besides that, I didn’t have to change anything else. Here is what my item_list call looks like now:

item_list = JSONImageItemList.from_folder(PATH/'train', extensions=[".txt"])

Hopefully this can help somebody else that is having similar issues.

5 Likes