Last active
March 3, 2018 10:49
-
-
Save wareya/ec9f33ce8e5c12f5005b5345ddcd7e6b to your computer and use it in GitHub Desktop.
execution code for vocalsoundfilter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!python | |
| # -*- coding: utf-8 -*- | |
| import numpy as np | |
| from random import shuffle, seed, randrange, choice, uniform | |
| from math import floor | |
| lines = [] | |
| data = [] | |
| low = 0x3000 | |
| high = 0x30FA | |
| simple_cjk = high-low+1 # kana or punctuation | |
| classes = simple_cjk+2 # one is below, one is above | |
| with open("test.txt", "r", encoding="utf-8") as f: | |
| for line in f: | |
| lines += [line] | |
| real_line = [] | |
| for c in line: | |
| char = [0]*classes | |
| num = ord(c) | |
| num -= low | |
| num += 1 | |
| if num < 0: | |
| num = 0 | |
| if num > classes-1: | |
| num = classes-1 | |
| char[num] = 1 | |
| real_line += [char] | |
| data += [np.array([real_line])] | |
| from keras.models import load_model | |
| model = load_model("model.h5") | |
| positive = False | |
| # necessary to prevent transcoding ~ and 〜 | |
| import sys | |
| def print(string): | |
| sys.stdout.buffer.write(str(string).encode('utf-8')) | |
| sys.stdout.buffer.write("\n".encode('utf-8')) | |
| for i in range(len(lines)): | |
| line = lines[i] | |
| if len(line) == 0: | |
| if positive: | |
| pass | |
| else: | |
| print(line) | |
| else: | |
| mydata = data[i] | |
| test = model.predict(mydata)[0] | |
| if (test[1] > test[0]) == positive: | |
| print(line.rstrip("\n")) | |
| exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment