Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import math
import random
import os
import cPickle as pickle
import _pickle as pickle
import xml.etree.ElementTree as ET

from utils import *
Expand Down Expand Up @@ -208,9 +208,13 @@ def to_one_hot(s, ascii_steps, alphabet):
if len(seq) >= ascii_steps:
seq = seq[:ascii_steps]
else:
seq = seq + [0]*(ascii_steps - len(seq))
one_hot = np.zeros((ascii_steps,len(alphabet)+1))
one_hot[np.arange(ascii_steps),seq] = 1
#print(ascii_steps - len(seq))
seq = seq + np.multiply([0],(ascii_steps - len(seq)))
one_hot = np.zeros((int(ascii_steps),len(alphabet)+1))
seq=np.array(seq,dtype=int)
seq=np.pad(seq,(0,len(np.arange(ascii_steps))-len(seq)))

one_hot[np.arange(ascii_steps,dtype=int),seq] = 1
return one_hot

# abstraction for logging
Expand All @@ -221,6 +225,6 @@ def __init__(self, args):

def write(self, s, print_it=True):
if print_it:
print s
print(s)
with open(self.logf, 'a') as f:
f.write(s + "\n")