-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_model.py
85 lines (68 loc) · 3.06 KB
/
load_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import csv
import itertools
import operator
import numpy as np
import nltk
import h5py
import os
from datetime import datetime
from keras.models import Sequential
from keras.layers import Dense, Activation,TimeDistributed
from keras.layers import LSTM,GRU
from keras.layers.embeddings import Embedding
from keras.optimizers import RMSprop, Adam
from keras.utils.data_utils import get_file
from keras.layers import Dropout
import numpy as np
import random
import sys
from keras.utils.np_utils import to_categorical
from keras.preprocessing import sequence
from keras.models import model_from_json
from make_smile import zinc_data_with_bracket_original, zinc_processed_with_bracket
def prepare_data(smiles,all_smile):
all_smile_index=[]
for i in range(len(all_smile)):
smile_index=[]
for j in range(len(all_smile[i])):
smile_index.append(smiles.index(all_smile[i][j]))
all_smile_index.append(smile_index)
X_train=all_smile_index
y_train=[]
for i in range(len(X_train)):
x1=X_train[i]
x2=x1[1:len(x1)]
x2.append(0)
y_train.append(x2)
return X_train,y_train
def loaded_model():
#json_file = open('/home/terayama/chem/virtual_loss_wv_pcclarge/wavemodel/model.json', 'r')
#json_file = open('/home/terayama/chem/ChemTS/train_RNN/model_zinc_LSTM256LSTM256_epoch20.json', 'r')
json_file = open('/home/terayama/chem/ChemTS/train_RNN/model_zinc250k_std_woSsP+-_LSTM256tanh_LSTM256tanh_epoch20.json', 'r')
#json_file = open('/Users/yang/wavemodel/model.json', 'r')
#json_file = open('/Users/yang/LSTM-chemical-project/protein-ligand/model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
#loaded_model.load_weights('/Users/yang/LSTM-chemical-project/protein-ligand/model.h5')
#loaded_model.load_weights('/home/terayama/chem/virtual_loss_wv_pcclarge/wavemodel/model.h5')
#loaded_model.load_weights('/home/terayama/chem/ChemTS/train_RNN/model_zinc_LSTM256LSTM256_epoch20.h5')
loaded_model.load_weights('/home/terayama/chem/ChemTS/train_RNN/model_zinc250k_std_woSsP+-_LSTM256tanh_LSTM256tanh_epoch20.h5')
#loaded_model.load_weights('/Users/yang/wavemodel/model.h5')
print("Loaded model from disk")
return loaded_model
def loaded_activity_model():
#smile_old=zinc_data_with_bracket_original()
#valcabulary,smile=zinc_processed_with_bracket(smile_old)
#json_file = open('/Users/yang/LSTM-chemical-project/new-version-rnn/model/model.json', 'r')
json_file = open('/Users/yang/LSTM-chemical-project/protein-ligand/ppara_model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights('/Users/yang/LSTM-chemical-project/protein-ligand/ppara_model.h5')
#loaded_model.load_weights('/Users/yang/LSTM-chemical-project/new-version-rnn/model/model.h5')
print("Loaded model from disk")
return loaded_model
#loaded_model()