I am trying to make a custom image list to create a databunch for a siamese network. i found this very helpful notebook:
however this uses the version 1.0.39 of fast ai. now, in the latest version, ImageItemList was replaced by ImageList. after changing that i get this error: ’SiamImageItemList’ object has no attribute 'xtra’
which is instigated by these lines in the SiamImageItemList:
imgs = self.xtra.Image.values
ids = self.xtra.Id.values
It inherits from ItemList and overwrite ItemList.get to call open_image in order to turn an image file in Path object into an Image object. label_cls can be specified for the labels, xtra contains any extra information (usually in the form of a dataframe) and processor is applied to the ItemList after splitting and labelling.
update: xtra was an attribute in the old version of fast ai v1. now its called inner_df.
jeremy should at least document such API breaking changes, its really hard to keep up with these, especially since they take place ever so often, and i had to dig deep into the docs to find out.
This siamese architecture by fastai is useful for me, thanks a lot.
And I have another question about how to prediction:
for example, in Jeremy’s course Image classification, it did prediction just like
i believe that will not work for you. that shouldn’t be the a problem tho, you can easily implement prediction in pure pytorch. But prediction for siamese is going to be different in the sense that you will need a support set (images with known classes) and a test set containing test images each of which you will compare compare to the images in the support set and find the most similar one. thats how siamese networks do predictions. so you can see that fastai’s predict method will not work for this.
as @mohamed1said, it can’t be implemented by fastai function directly. you need to use pytorch to achieve that. you should process your image to tensor format:
crop image to fulfill network size.
normalize image (cause ‘dist’ should in a range e.g. [0, 1] so that you can do some strategy)
transfer images to tensor format and add 1 dimension (cause the network we train is using batch data, the network expect your input is [batch_size, channel_size, pixel, pixel], so you should add 1D be [1, channel_size, pixel, pixel]
you should determine ‘pred_target’ based on the threshold, the threshold will be calculated by validation data.