def test_data_path():
    s = data_path()
    assert isinstance(s, Path) and s != "" and os.path.isdir(
        str(s)) and s.name == "data"
Example #2
0
    for p in all_val_videos_path[:NUM_OF_SAMPLES_VAL]:

        class_id = LABELS.index(p.split('/')[-2])
        entry = '{},{}'.format(p.replace('.mp4', ''), class_id)

        filehandle.write('%s\n' % entry)
##
NUM_FRAMES = 32  # 8 or 32.
IM_SCALE = 128  # resize then crop
INPUT_SIZE = 112  # input clip size: 3 x NUM_FRAMES x 112 x 112

# video sample to download
sample_video_url = Urls.webcam_vid

# file path to save video sample
video_fpath = data_path() / "sample_video.mp4"

# prediction score threshold
SCORE_THRESHOLD = 0.01

# Averaging 5 latest clips to make video-level prediction (or smoothing)
AVERAGING_SIZE = 5

##

if BASE_MODEL == "kinetics":
    BATCH_SIZE_ARRAY = [8, 1, 4, 5, 6]
    MODEL_INPUT_SIZE = 32
elif BASE_MODEL == "r2plus1d_18":
    BATCH_SIZE_ARRAY = [8, 1, 16, 20, 20]
    MODEL_INPUT_SIZE = 16
def test__DatasetSpec_hmdb():
    """ Tests DatasetSpec initialize with hmdb51 classes """
    hmdb51 = _DatasetSpec(Urls.hmdb51_label_map, 51)
    hmdb51.class_names
    assert os.path.exists(str(data_path() / "label_map.txt"))
Example #4
0
# models.vgg19_bn 	models.wrn 	models.wrn_22
# models.xception 	models.xresnet 	models.xresnet101
# models.xresnet152 	models.xresnet18 	models.xresnet34
# models.xresnet50
model = model_to_learner(models.resnet18(pretrained=True), IMAGENET_IM_SIZE)
#learn = model_to_learner(models.resnet152(pretrained=True), IMAGENET_IM_SIZE)
#learn = model_to_learner(models.xresnet152(pretrained=True), IMAGENET_IM_SIZE)

# TODO: Want to load from local copy rather than from ~/.torch? Maybe
#learn = load_learner(file="resnet18-5c106cde.pth")

#model = untar_data("resnet18-5c106cde.pth")
#learn = load_learner(model)

# TODO Handle folder of images.

for path in args.path:

    if is_url(path):
        imfile = os.path.join(data_path(), "temp.jpg")
        urllib.request.urlretrieve(path, imfile)
    else:
        imfile = os.path.join(get_cmd_cwd(), path)

    im = open_image(imfile, convert_mode='RGB')

    # Predict the class label.

    _, ind, prob = model.predict(im)
    sys.stdout.write(f"{prob[ind]:.2f},{labels[ind]},{path}\n")
def test__DatasetSpec_kinetics():
    """ Tests DatasetSpec initialize with kinetics classes """
    kinetics = _DatasetSpec(Urls.kinetics_label_map, 400)
    kinetics.class_names
    assert os.path.exists(str(data_path() / "label_map.txt"))