示例#1
0
def plot_val_with_title(idxs, title):
    imgs = np.stack([data.val_ds[x][0] for x in idxs])
    title_probs = [probs[x] for x in idxs]
    print(title)
    return plots(data.val_ds.denorm(imgs), rows=1, titles=title_probs)
示例#2
0
def plotXY(x, y):
    plots([x])
    plt.gca().add_patch(create_rect(y))
示例#3
0
def plot_val_with_title(idxs, title):
    imgs = [load_img_id(data.val_ds, x) for x in idxs]
    title_probs = [probs[x] for x in idxs]
    print(title)
    return plots(imgs, rows=1, titles=title_probs, figsize=(16, 8))
示例#4
0
plotXY(x, y)

# ## Scale

# In[14]:

xx, yy = Scale(sz=350, tfm_y=TfmType.COORD)(x, y)

# In[15]:

plotXY(xx, yy)

# In[16]:

xx, yy = Scale(sz=350, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])

# ## RandomScale

# In[17]:

xx, yy = RandomScale(sz=350, max_zoom=1.1, tfm_y=TfmType.COORD)(x, y)
plotXY(xx, yy)
print(yy)
print(y)

# In[18]:

xx, yy = RandomScale(sz=350, max_zoom=1.1, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])
示例#5
0
                                                    classes=['dogs', 'cats'],
                                                    test_name='test',
                                                    tfms=tfms,
                                                    num_workers=1,
                                                    bs=2)
    x, _ = next(iter(data.aug_dl))
    return data.trn_ds.denorm(x)[1]


# In[ ]:

ims = np.stack([get_augs() for i in range(6)])

# In[ ]:

plots(ims, rows=2)

# Let's create a new `data` object that includes this augmentation in the transforms.

# In[ ]:

data = ImageClassifierData.from_names_and_array(path=PATH,
                                                fnames=fnames,
                                                y=labels,
                                                classes=['dogs', 'cats'],
                                                test_name='test',
                                                tfms=tfms)
learn = ConvLearner.pretrained(arch,
                               data,
                               precompute=True,
                               tmp_name=TMP_PATH,
示例#6
0
def plot_aug(tfms):
    ims = np.stack([get_augs(tfms) for i in range(6)])
    plots(ims, rows=2)
#%%
def plots(ims, figsize=(12, 6), rows=2, titles=None):
    f = plt.figure(figsize=figsize)
    cols = len(ims) // rows
    for i in range(len(ims)):
        sp = f.add_subplot(rows, cols, i + 1)
        sp.axis('Off')
        if titles is not None: sp.set_title(titles[i], fontsize=16)
        plt.imshow(ims[i], cmap='gray')


#%%
plots(imgs[:8],
      titles=[
          class_names[test_preds[0]], class_names[test_preds[1]],
          class_names[test_preds[2]], class_names[test_preds[3]],
          class_names[test_preds[4]], class_names[test_preds[5]],
          class_names[test_preds[6]],
          str(data.classes[preds])
      ])

#%% #Predict on test set This step is under construction...
acc = 0
test_log_preds = np.zeros([7, 60, 7])
preds_test = np.zeros([7, 60, 7])
for insects in data.classes:
    data = ImageClassifierData.from_paths(PATH,
                                          bs=bsz,
                                          tfms=tfms_from_model(arch, sz),
                                          test_name='test/' + insects)
    learn = ConvLearner.pretrained(arch, data)
    test_log_preds[[data.classes.index(insects)]] = learn.predict(is_test=True)
示例#8
0
# We can look at part of an image:

# In[19]:

x_imgs[0, 10:15, 10:15]

# In[20]:

show(x_imgs[0, 10:15, 10:15])

# In[21]:

plots(x_imgs[:8],
      titles=[
          class_names[y_valid[0]], class_names[y_valid[1]],
          class_names[y_valid[2]], class_names[y_valid[3]],
          class_names[y_valid[4]], class_names[y_valid[5]],
          class_names[y_valid[6]], class_names[y_valid[7]]
      ])

# In[14]:

from fastai.metrics import *
from fastai.model import *
from fastai.dataset import *
from fastai.plots import *

import torch.nn as nn

# We will begin with the highest level abstraction: using a neural net defined by PyTorch's Sequential class.
#%%