Skip to content

Instantly share code, notes, and snippets.

import os,pymysql.cursors
def get_error_ids():
ids=[]
img_paths = os.listdir('./')
for img_path in img_paths:
if 'sale-error' not in img_path: continue
_id = img_path.split('-')[0]
ids.append(_id)
return ids
lis = []
new_df = raw_df['text'].apply(lambda x :prepro(x))
for i in range(len(new_df)):
# print(new_df[i:i+1].values[0])
lis.append(new_df[i:i+1].values[0])
print(lis)
new_df = pd.DataFrame(lis)
new_df
@sleepless-se
sleepless-se / to_index_word.py
Last active February 12, 2019 01:28
Keras word_index to index2word dict
index2word = {i+1:key for i, key in enumerate(token.word_index)}
@sleepless-se
sleepless-se / hash.py
Created February 13, 2019 21:13 — forked from nmalkin/hash.py
SHA-256 hash of a string in Python 3
#!/usr/bin/env python3
import hashlib
def hash_string(string):
"""
Return a SHA-256 hash of the given string
"""
return hashlib.sha256(string.encode('utf-8')).hexdigest()
@sleepless-se
sleepless-se / keras_rl_sample.py
Created February 21, 2019 12:32
強化学習サンプル Keras-RL
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
from keras.optimizers import Adam
import gym
from rl.agents.dqn import DQNAgent
from rl.policy import EpsGreedyQPolicy
from rl.memory import SequentialMemory
env = gym.make('MountainCar-v0')
nb_actions = env.action_space.n
@sleepless-se
sleepless-se / mountain_car.py
Created February 21, 2019 13:09
強化学習サンプル MountainCar-v0
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
from keras.optimizers import Adam
import gym
from rl.agents.dqn import DQNAgent
from rl.policy import EpsGreedyQPolicy
from rl.memory import SequentialMemory
env = gym.make('MountainCar-v0')
nb_actions = env.action_space.n
@sleepless-se
sleepless-se / dict.txt
Last active February 25, 2019 19:03
文章を書く時に役立つ「日本語→英語」変換辞書。プログラミングやブログで使う単語中心ですがそれ以外もOK
じぇいそーぷ jsoup 名詞
くらす <div class=""></div> 名詞
しゅってん: 出典: 名詞
みだし <h2></h2> 名詞
みだし <h3></h3> 名詞
みだし <h4></h4> 名詞
hr <hr> 名詞
h4 <h4></h4> 名詞
h3 <h3></h3> 名詞
h2 <h2></h2> 名詞
@sleepless-se
sleepless-se / get_object_center.py
Created February 27, 2019 00:52
Get object's center
def get_object_center(rois,image):
height = image.shape[0]
width = image.shape[1]
center = width / 2
print(width,height)
print('center',center)
max_area = 0
for i in range(len(rois)):
print(rois[i])
start_height = rois[i][0]
@sleepless-se
sleepless-se / left_right_image.py
Last active February 27, 2019 04:22
Make left rigth split image from image path.
def left_right_image(left_img_path,right_img_path, canvas_size = 500):
# load image
iml = Image.open(left_img_path)
imr = Image.open(right_img_path)
# make back ground
bg = Image.new("RGB",(canvas_size,canvas_size),(250,250,250))
# target position
left_target = int(bg.size[0] / 4 * 1)
@sleepless-se
sleepless-se / make_mask.py
Created February 27, 2019 05:43
make_maks by PIL
def make_mask(size,start_width,start_height,end_width,end_height):
mask = Image.new("L",(size,size),0)
draw = ImageDraw.Draw(mask)
draw.rectangle((start_width,start_height,end_width,end_height), fill=255)
print('mask',mask.size)
return mask