Virtual memory
code snippets for things I regularly forget how to do
Use Mambda instead of conda to install packages.
We've done what we do at @QuantStack: making things run faster. Conda has been getting slower with @condaforge's growing package registry -- we're fighting it with raw C++ power in the #mamba package!
— Wolf Vollprecht (@wuoulf) March 25, 2019
Try now:
conda install mamba -c conda-forge/label/mamba-alpha -c conda-forge pic.twitter.com/tnlVQKAbv4
import pandas as pd
rows = ['1', '2', '3', '2','1']; df = pd.DataFrame({'a':rows, 'b': rows})
df
df[df.groupby('a')['a'].transform('count').ge(2)]
from fastai.vision.all import *
Train a learner so we can do some inference
path = untar_data(URLs.PETS)
files = get_image_files(path/"images")
def label_func(f): return f[0].isupper()
dls = ImageDataLoaders.from_name_func(path, files, label_func, item_tfms=Resize(32), num_workers=0)
dls.show_batch()
learn = cnn_learner(dls, resnet18, metrics=error_rate)
learn.fine_tune(1)
preds = learn.get_preds()
dls.categorize.decode(0)
If we have the predictions tensors i.e. the predictions for each class:
preds[0][0]
numpy argmax
can be used to get the index of the most likely predictions`
dls.categorize.decode(np.argmax(preds[0][0]))
Can also access the confidence for the maximum prediction directly;
max(preds[0][0])
dls = ImageDataLoaders.from_name_func(path, files, label_func, item_tfms=Resize(32), batch_tfms=[*aug_transforms()],num_workers=0)
learn = cnn_learner(dls, resnet18, metrics=error_rate)
learn.fit(1)
doc(learn.tta)
preds, targs = learn.tta()
error_rate(preds, targs).item()
Accessing the input from the data loaders can be done through items
. The L
here is just to automagically limit the number of items displayed in the notebook
L(dls.items)
dls.items[0]
Filtering repositories
If you end up with a big repository which you want to split off into a new repo but maintain the history for the stuff in that folder. Use https://github.com/newren/git-filter-repo/ to filter the repo itself. To do this I pulled the old repo into a new folder to make sure I didn't destroy anything by mistake. You filter out a repo based on a folder and other potential filters. Once this repo has been filtered you can push it to a new repo.