Skip to content

Instantly share code, notes, and snippets.

jeakwon

Block or report user

Report or block jeakwon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View main.py
import time
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import DataLoader, random_split
from torchvision import datasets, transforms
from activation import load_actF
@jeakwon
jeakwon / argparse_dict_argument.py
Created Oct 31, 2019 — forked from vadimkantorov/argparse_dict_argument.py
A one-line example enabling Python's argparse to accept dictionary arguments
View argparse_dict_argument.py
# Example:
# $ python argparse_dict_argument.py --env a=b --env aa=bb
# Namespace(env={'a': 'b', 'aa': 'bb'})
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--env', action = type('', (argparse.Action, ), dict(__call__ = lambda a, p, n, v, o: getattr(n, a.dest).update(dict([v.split('=')])))), default = {}) # anonymously subclassing argparse.Action
print parser.parse_args()
@jeakwon
jeakwon / tag.py
Last active Oct 28, 2019
easy metrics for pytorch
View tag.py
import time
import torch
class Tag:
def __init__(self, topk=(1,), verbose=True):
self.__topk = topk
self.__verbose = verbose
def __call__(self, data_loader):
self.__time_start = time.time()
@jeakwon
jeakwon / tag.py
Created Oct 27, 2019
pytorch tag class for metrics
View tag.py
import time
import torch
class AverageMeter:
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
View data_loader.py
"""
Create train, valid, test iterators for CIFAR-10 [1].
Easily extended to MNIST, CIFAR-100 and Imagenet.
[1]: https://discuss.pytorch.org/t/feedback-on-pytorch-for-kaggle-competitions/2252/4
"""
import torch
import numpy as np
from utils import plot_images
@jeakwon
jeakwon / sr_with_timestamp_from_wav_mono.py
Created Jun 24, 2019
speech recognition of Korean wav (mono)
View sr_with_timestamp_from_wav_mono.py
# Cutting .wav file from start to end
# ffmpeg -i <in_file> -ss <start_sec> -to <end_sec> -c copy <out_file>
# ffmpeg -i 1.mp3 -ss 0 -to 60 -c copy 2.mp3 (example of use)
# Generating mono .wav file
# ffmpeg -i <in_file> -acodec pcm_s16le -ac 1 -ar 16000 <out_file>
# ffmpeg -i 2.mp3 -acodec pcm_s16le -ac 1 -ar 16000 2.wav
# Combine both
# ffmpeg -i 1.mp3 -ss 0 -to 60 -c -acodec pcm_s16le -ac 1 -ar 16000 copy out.wav
@jeakwon
jeakwon / sr_with_timestamp.py
Created Jun 24, 2019
google_cloud_speech_recognition.py
View sr_with_timestamp.py
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="<credential_file>.json"
def transcribe_gcs_with_word_time_offsets(gcs_uri):
"""Transcribe the given audio file asynchronously and output the word time
offsets."""
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
client = speech.SpeechClient()
@jeakwon
jeakwon / runtime.py
Created May 8, 2019
runtime_decorator
View runtime.py
def runtime(func):
@wraps(func)
def decorated(*args, **kwargs):
# Decorate front of func
before = time.time()
output = func(*args, **kwargs)
# Decorate back of func
after = time.time()
View logger.py
# -*- coding: utf-8 -*-
import logging.handlers
class Setting:
"""로거 세팅 클래스
::
Setting.LEVEL = logging.INFO # INFO 이상만 로그를 작성
"""
@jeakwon
jeakwon / setup.py
Created Feb 18, 2019
setup.py with markdown
View setup.py
from setuptools import setup, find_packages
with open('README.md', encoding='utf-8') as f:
long_description = f.read()
setup(
name = 'ypcc',
version = '0.6.6',
long_description = long_description,
long_description_content_type='text/markdown',
description = 'ccpy',
You can’t perform that action at this time.