Skip to content

Instantly share code, notes, and snippets.

@yusuke0519
yusuke0519 / recursive_setattr.py
Last active September 16, 2022 12:29
再帰的なsetattr(nameが"."を含む場合のsetattr)
def recursive_setattr(obj, name, value):
if '.' in name:
parent, child = name.split('.')[0], '.'.join(name.split('.')[1:])
recursive_setattr(getattr(obj, parent), child, value)
else:
setattr(obj, name, value)
@yusuke0519
yusuke0519 / args_to_wandb_query.py
Last active February 10, 2021 08:48
In many cases, including hyperparameter search, we want to check whether the same config has been already finished or not, This is a short examples for checking it when we uses wandb as a backend.
""" Argparser to wandb query.
References
----------
Short tutorial: https://docs.wandb.ai/ref/export-api
Wandb API: https://docs.wandb.ai/ref/export-api/api
- Api.runs
- RUN class
Mongodb query: https://docs.mongodb.com/manual/reference/operator/query/
"""
@yusuke0519
yusuke0519 / get_activation_pytorch.py
Last active February 2, 2021 10:01
Store activations during the forward path using hooks.
class MLPEncoder(nn.Module):
def __init__(self):
super(MLPEncoder, self).__init__()
# TODO: Fix hard coding
self.model = nn.Sequential(OrderedDict([
('layer1', nn.Linear(784, 400)),
('relu1', nn.ReLU()),
('layer2', nn.Linear(400, 400)),
('relu2', nn.ReLU()),
@yusuke0519
yusuke0519 / central_mean_diescrepancy.py
Created April 12, 2019 03:25
PyTorch implementation of central mean discrepancy (https://arxiv.org/abs/1702.08811)
# # -*- coding: utf-8 -*-
import itertools
from torch.utils import data
def l2diff(x1, x2):
"""
standard euclidean norm
"""
return ((x1-x2)**2).sum().sqrt()
@yusuke0519
yusuke0519 / sacred_wrap.py
Created March 8, 2019 08:51
Sacred Wrapper
# # -*- coding: utf-8 -*-
"""Utils to handle saved information in mongodb."""
from future.utils import iteritems
import pandas as pd
from pymongo import MongoClient
def expand_config(config):
@yusuke0519
yusuke0519 / temped_softmax_gradient.py
Last active November 14, 2016 07:29
温度付きsoftmaxの勾配の大きさの確認
import keras.backend as K
import numpy as np
from keras.layers import Input, Dense, Lambda, Activation
from keras.models import Model
def temped_softmax(x, T=1):
"""Compute softmax values for each sets of scores in x."""
return np.exp(x/T) / np.sum(np.exp(x/T), axis=0)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yusuke0519
yusuke0519 / google_stv_image_api.ipynb
Created February 19, 2016 04:12
google street view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yusuke0519
yusuke0519 / geojson_googlmap_with_bokeh.ipynb
Created February 19, 2016 01:52
bokeh, Google Map, geojson
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.