I wrote a piace of code just now. It makes use of the fastai augmentation api. You can use it for generating a new dataset which has the transformation you desire.
from fastai import *
from fastai.vision import *
from fastai.imports import *
import matplotlib.image as IM
# Example:
#
# TR = gettransfs()
#
# transfy(TR, '/data/apath', variants=5)
def gettransfs(do_flip=False, max_rotate=90, **kwargs):
tfms = get_transforms(do_flip=do_flip, max_rotate=90, **kwargs)
return tfms
def transfy(tfms, rootpath, variants=1, newdir='AUGM', tree_structure=True, include_source=True, **kwargs):
PATH=rootpath
if not os.path.exists(PATH):
print('Path does not exist.')
return 0
else: print('Working in '+PATH)
os.chdir(PATH)
workdir = PATH
if not os.path.exists(f'{workdir}/../'+newdir):
os.mkdir(f'{workdir}/../'+newdir)
content = os.listdir(workdir)
subfolders = [item for item in content if os.path.isdir(item)]
print('Classes (subfolders) found: '), print(len(subfolders))
if tree_structure:
for folder in subfolders:
if not os.path.exists(f'{workdir}/../'+newdir+'/'+folder): os.mkdir(f'{workdir}/../'+newdir+'/'+folder)
for folder in subfolders:
os.chdir(f'{workdir}/'+folder)
currentd=os.getcwd().replace('\\','/')
filelist=os.listdir(currentd)
print('Visiting '+currentd)
#verify_images(currentd)
#commented since it's dangerous
if tree_structure:
dest=os.path.abspath((f'{workdir}/../'+newdir+'/'+folder)).replace('\\','/')
else:
dest=os.path.abspath((f'{workdir}/../'+newdir)).replace('\\','/')
for file_idx in filelist:
current_img = open_image(currentd+'/'+file_idx)
if include_source:
shutil.copyfile(currentd+'/'+file_idx, dest+'/'+file_idx)
for i in range(variants):
currenttsfimg=apply_tfms(tfms[0], current_img, size=299, **kwargs)
currenttsfimgnp=image2np(currenttsfimg.data)
IM.imsave(os.path.splitext(dest+'/'+file_idx)[0]+'_'+str(i+2)+os.path.splitext(dest+'/'+file_idx)[1],
currenttsfimgnp)
print('Finished')
You got to give to these two functions the proper kwargs based on your needs, but for testing purposes try what’s suggested in the comment. I’ll put it in a specific thread, maybe some other people could find it useful.
Coming to the original question:
Pretrained is not so important when it comes to speed. The only difference is that when False, the weights are randomly (in fact, I think a la Xavier) initialized, whereas when True, they are initialized with their Imagenetlike values. In both cases, the training must go on along the whole network.
With a frozen model, however, the weights need not to be updated, apart from the custom head, but the frozen part still needs to (unnecessarily, indeed, if you do no aug) compute the activations.
Back when precompute was available, the frozen part was actually dormant: since the weights were always the same as well as the data points, the nodes would spit out always the same activations. Only the head was active (both weight updating and activations’ computation).