<commit_before>#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse

import chainer
import chainer.optimizers as O
import chainer.serializers as S

import fcn
from fcn.models import FCN32s
from fcn.models import VGG16

from dataset import JskSemantics201607Dataset


def get_vgg16_pretrained_model(n_class):
    vgg16_path = fcn.setup.download_vgg16_chainermodel()
    vgg16 = VGG16()
    print('Loading vgg16 model: {0}'.format(vgg16_path))
    S.load_hdf5(vgg16_path, vgg16)
    return vgg16


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-g', '--gpu', type=int, default=0)
    args = parser.parse_args()

    gpu = args.gpu

    dataset = JskSemantics201607Dataset()
    n_class = len(dataset.target_names)

    # setup model
    pretrained_model = get_vgg16_pretrained_model(n_class)
    model = FCN32s(n_class=n_class)
    fcn.util.copy_chainermodel(pretrained_model, model)
    if gpu != -1:
        model.to_gpu(gpu)

    # setup optimizer
    # optimizer = O.MomentumSGD(lr=1e-8, momentum=0.99)
    optimizer = O.Adam(alpha=1e-5)
    optimizer.setup(model)
    optimizer.add_hook(chainer.optimizer.GradientClipping(threshold=5))

    # train
    trainer = fcn.Trainer(
        dataset=dataset,
        model=model,
        optimizer=optimizer,
        weight_decay=0.0005,
        test_interval=1000,
        max_iter=20000,
        snapshot=1000,
        gpu=gpu,
    )
    trainer.train()


if __name__ == '__main__':
    main()<commit_msg>Smaller iteration<commit_after>#!/usr/bin/env python

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse

import chainer
import chainer.optimizers as O
import chainer.serializers as S

import fcn
from fcn.models import FCN32s
from fcn.models import VGG16

from dataset import JskSemantics201607Dataset


def get_vgg16_pretrained_model(n_class):
    vgg16_path = fcn.setup.download_vgg16_chainermodel()
    vgg16 = VGG16()
    print('Loading vgg16 model: {0}'.format(vgg16_path))
    S.load_hdf5(vgg16_path, vgg16)
    return vgg16


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-g', '--gpu', type=int, default=0)
    args = parser.parse_args()

    gpu = args.gpu

    dataset = JskSemantics201607Dataset()
    n_class = len(dataset.target_names)

    # setup model
    pretrained_model = get_vgg16_pretrained_model(n_class)
    model = FCN32s(n_class=n_class)
    fcn.util.copy_chainermodel(pretrained_model, model)
    if gpu != -1:
        model.to_gpu(gpu)

    # setup optimizer
    # optimizer = O.MomentumSGD(lr=1e-8, momentum=0.99)
    optimizer = O.Adam(alpha=1e-5)
    optimizer.setup(model)
    optimizer.add_hook(chainer.optimizer.GradientClipping(threshold=5))

    # train
    trainer = fcn.Trainer(
        dataset=dataset,
        model=model,
        optimizer=optimizer,
        weight_decay=0.0005,
        test_interval=100,
        max_iter=5000,
        snapshot=100,
        gpu=gpu,
    )
    trainer.train()


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.09635499207606973, 'fraction_numerical': 0.043423137876386686, 'mean_word_length': 3.4702549575070822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145326', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1113, 'n_words': 214}