I’m using TTA in an image classification task like so:
my_tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=45, max_zoom=1.2, max_lighting=0.2,
max_warp=None, p_affine=1, p_lighting=.5)
data = ImageDataBunch.from_csv(path=DATAPATH, folder='images_resized',
csv_labels='my_labels.csv', valid_pct=.15, header=None,
fn_col=0, label_col=1, ds_tfms=my_tfms, size=224, bs=40)
learner = create_cnn(data, models.resnet34, metrics=accuracy)
- What are the transforms that TTA uses for its augmentations? I’m guessing it’s not the “my_tfms” that were used to define the original databunch, right? Is there a default set of transforms that TTA uses?
- I’d like to run TTA on a new dataset (found in a new csv, e.g. my_labels2.csv). How would I do this?
TTA uses the transforms you defined on the training set (with some tweaks to make sure to look at the four corners).
To run it on a new dataset, define is as the test set of your
DataBunch then run
Thanks @sgugger !
This forced me to look a little bit deeper into how data is loaded into the learner. In case anyone’s interested, I wound up loading my ‘test’ data into the ‘validation’ slot of the learner, as seen below (need to first run the code above):
df_data = pd.read_csv(DATAPATH/'my_labels.csv')
df_test_data = pd.read_csv(DATAPATH/'my_test_labels.csv')
learner.data = data_test
add_test didn’t work?
@sgugger , from what I understand, fastai test datasets have no labels (https://docs.fast.ai/data_block.html#Add-a-test-set), so I decided to add the test set as the validation set, so I could include labels with it.
@sgugger is there somewhere I can find a list of the exact transforms that TTA uses? You mentioned “tweaks to make sure to look at the four corners” as one difference from that used on the train set…
I’d like to use them on the validation set with get_preds so I can save the outputs of each of the 8 variations. Currently I’m doing:
but it gives a slightly worse accuracy when averaging predictions compared to doing learner.TTA()
You should check the source code to have more details. I didn’t write the TTA part so I don’t know more than I told you already
ok, thanks anyway. Averaging the 8 versions gets pretty close, so I’ll probably stick with that. In case anyone’s wondering, here’s the code I’m using:
learner1 = cnn_learner(data_test1, models.resnet34, metrics=accuracy,pretrained=True)
I was also wondering how to use TTA in the 2019 version of Fastai and came across this thread. While it was covered in the 2018 course and notebooks, I don’t recall it being mentioned or used in the 2019 course.
Is it still useful and effective in improving prediction accuracy with the 2019 version of fastai?