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
Last active November 27, 2019 07:40
Implementation in pytorch
```
Example of Usage
---
visualize_targets = [
'key of your network layer',
'for example:',
'conv1',
'residual_block1.conv1',
'residual_block1.conv2'
]
@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 / 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 / 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 / focal_loss.py
Last active November 27, 2019 07:39
focal loss implemented with chainer
import chainer.functions as F
try:
from chainer.backend import get_array_module
except: # if you don't use cuda
import numpy as np
get_array_module = lambda x: np
def focal_loss(y_pred, y_true, scale=2):
xp = get_array_module(y_pred)
@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