Skip to content

Instantly share code, notes, and snippets.

@TeraBytesMemory
TeraBytesMemory / Vagrantfile
Last active March 4, 2018 03:57
Windows10 on Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "Microsoft/EdgeOnWindows10"
config.vm.box_version = "1.0"
config.vm.provider "virtualbox" do |vb|
# guiの設定
vb.gui = true
from notebook.base.handlers import APIHandler as IPyAPIHandler
import json
class APIHandler(IPyAPIHandler):
def set_default_headers(self):
self.set_header('Content-Type', 'application/json')
def finish(self, chunk=None):
if type(chunk) == dict:
# encode: utf-8
from flask.views import MethodView
from flask import request, Response, json
import os
import re
OAUTH_BEAR_TOKEN = os.environ.get('OAUTH_BEAR_TOKEN')
@TeraBytesMemory
TeraBytesMemory / logger_factory.py
Created February 15, 2019 08:19
My logger factory
# coding: utf-8
from logging import getLogger, Formatter, StreamHandler
import logging
def logger(
logger_name='',
level=logging.DEBUG,
Handler=StreamHandler,
@TeraBytesMemory
TeraBytesMemory / grad_cam.py
Created June 6, 2019 09:48
Grad CAM implementation with chainer v6.0.0
import chainer
import chainer.functions as F
from chainer import LinkHook
from typing import List, Optional
import cv2
class IntermidateCache(LinkHook):
def __init__(self, layer: chainer.Chain):
layer.add_hook(self)
@TeraBytesMemory
TeraBytesMemory / spatial_dropout.py
Last active June 27, 2019 05:43
Implementation spatial dropout with chainer
import chainer
import chainer.functions as F
class Dropout1d(chainer.Chain):
'''
spatial dropout module (1d)
'''
def __init__(self, raito=.5):
super().__init__()
@TeraBytesMemory
TeraBytesMemory / loss_and_acc.py
Last active June 27, 2019 05:44
segmentation loss (cross entropy plus dice coef) and accuracy (IoU score) in chainer
# coding: utf-8
import chainer
import chainer.functions as F
import chainer.links as L
try:
from chainer.backend import get_array_module
except:
import numpy as np
@TeraBytesMemory
TeraBytesMemory / data_manager.py
Last active July 17, 2019 06:22
[WIP] multimodal dataset manager (local storage and google cloud storage)
# coding: utf-8
from io import BytesIO
import cv2
from fnmatch import fnmatch
from google.cloud.storage import Client, Blob
import numpy as np
import pandas as pd
import os.path
from pathlib import Path
import MeCab
class MeCabGenerator(object):
def __init__(self, dict_path='/usr/local/lib/mecab/dic/mecab-ipadic-neologd'):
self.mecab = MeCab.Tagger ('-d {}'.format(dict_path))
def parse(self, text):
return self._generator_wrapper(text)
def get_morphemes(self, text, surface_filter=lambda x: x):
import CaboCha
class CaboChaGenerator(object):
def __init__(self):
self.c = CaboCha.Parser()
def parse_to_chunk(self, text):
tree = self.c.parse(text)
for i in range(tree.chunk_size()):
chunk = tree.chunk(i)
chunk_tokens = [