Skip to content

Instantly share code, notes, and snippets.

View belltailjp's full-sized avatar

Daichi SUZUO belltailjp

View GitHub Profile
@belltailjp
belltailjp / prepare.sh
Last active November 1, 2017 07:35
chainer.links.ResNetXXLayers inaccurateness minimum reproduction code (Python 3.6, Chainer 3.0, CUDA8.0, cuDNN7) written for https://github.com/chainer/chainer/issues/3756
#!/bin/sh
wget http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_val.tar
tar xf ILSVRC2012_img_val.tar
wget http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz
tar xf caffe_ilsvrc12.tar.gz
@belltailjp
belltailjp / bench.py
Last active October 19, 2017 14:33
Draw 2D Gaussian Image using Cupy
import time
def measure_time_in_ms(func, n_times, size, sigma):
start = time.time()
for _ in range(n_times):
out = func(size, sigma)
assert(out.shape == (size, size))
elapsed_sec = time.time() - start
return elapsed_sec / n_times * 1000
input: "data"
input_dim: 1
input_dim: 3
input_dim: 368
input_dim: 368
layer {
name: "conv1_1"
type: "Convolution"
bottom: "data"
top: "conv1_1"
@belltailjp
belltailjp / process_safe_tqdm.py
Last active March 24, 2017 06:22
A dirty hack to make tqdm process safe http://daily.belltail.jp/?p=2389
import tqdm
import multiprocessing
class ProcessSafeTqdm(tqdm.tqdm):
def __init__(self, *args):
super(ProcessSafeTqdm, self).__init__(*args)
self.correct_count = multiprocessing.Value('i', 0)
def update(self, n=1):
with self.correct_count.get_lock():
@belltailjp
belltailjp / iou.py
Created March 22, 2017 06:45
Intersection over Union
def iou(r1, r2):
x1, y1, w1, h1 = r1
x2, y2, w2, h2 = r2
and_x1, and_y1 = max(x1, x2), max(y1, y2)
and_x2, and_y2 = min(x1 + w1, x2 + w2), min(y1 + h1, y2 + h2)
and_w = and_x2 - and_x1
and_h = and_y2 - and_y1
if and_w <= 0 or and_h <= 0:
return 0
and_area = and_w * and_h
@belltailjp
belltailjp / imdecode_bench.py
Last active February 15, 2017 07:28
Benchmark of OpenCV image decoding speed
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import time
import tqdm
import numpy
if __name__ == "__main__":
img = cv2.imread('image.jpg')
@belltailjp
belltailjp / search.rb
Created January 1, 2017 06:49
YouTube Data API v3 + google-api-ruby-client 0.9.20 example for searching movie Raw
require 'google/apis/youtube_v3'
require 'active_support/all'
GOOGLE_API_KEY="YOUR_API_KEY"
def find_videos(keyword, after: 1.months.ago, before: Time.now)
service = Google::Apis::YoutubeV3::YouTubeService.new
service.key = GOOGLE_API_KEY
next_page_token = nil
@belltailjp
belltailjp / calendar_demo.rb
Created May 30, 2016 13:10
An example of obtaining Google Calendar public events using ruby
require 'google/apis/calendar_v3'
require 'active_support'
require 'active_support/core_ext'
service = Google::Apis::CalendarV3::CalendarService.new
# change here so you can specify your own Google calendar API access key
service.key = ENV['GOOGLE_CALENDAR_API_KEY']
# Obtain every events within a year from 名古屋アジャイル勉強会 public calendar
require 'capybara'
require 'capybara/poltergeist'
def wait_for_ajax(session)
Timeout.timeout(Capybara.default_wait_time) do
return if session.evaluate_script('jQuery.active').blank?
loop until session.evaluate_script('jQuery.active').zero?
end
end
@belltailjp
belltailjp / toyota_stadium_geo.json
Last active December 15, 2015 15:27
Example of Google Geocoding API
% curl "https://maps.googleapis.com/maps/api/geocode/json?address=豊田スタジアム&language=ja&region=jp&key=YOUR_API_KEY" | jq "."
{
"results": [
{
"address_components": [
{
"long_name": "豊田スタジアム",
"short_name": "豊田スタジアム",
"types": [
"premise"