Skip to content

Commit

Permalink
Improved code and organization (bug fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
kk7nc committed Mar 27, 2018
1 parent 948d50f commit a52f008
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 19 deletions.
Binary file added Download/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Examples/MNIST.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
batch_size = 500
sparse_categorical = 0
n_epochs = [10, 500, 10] ## DNN--RNN-CNN
Random_Deep = [1, 0, 1] ## DNN--RNN-CNN
Random_Deep = [0, 0, 1] ## DNN--RNN-CNN
RMDL.Image_Classification(X_train, y_train, X_test, y_test, batch_size, shape, sparse_categorical, Random_Deep,
n_epochs)
16 changes: 8 additions & 8 deletions RMDL/BuildModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from keras.layers import Dense, Flatten
from keras.layers import Conv1D,MaxPooling2D, \
MaxPooling1D, Embedding, Merge, Dropout,\
GRU,TimeDistributed,Convolution2D,\
Activation,Convolution3D,GlobalAveragePooling3D,LSTM
GRU,TimeDistributed,Conv2D,\
Activation,Conv3D,GlobalAveragePooling3D,LSTM
from keras import backend as K
from keras.models import Model
from keras.layers import Input
Expand Down Expand Up @@ -149,14 +149,14 @@ def Image_model_CNN(num_classes,shape):
Layers = list(range(1, 4))
Layer = random.choice(Layers)
Filter = random.choice(values)
model.add(Convolution2D(Filter, 3, 3, border_mode='same', input_shape=shape))
model.add(Conv2D(Filter, (3, 3), padding='same', input_shape=shape))
model.add(Activation('relu'))
model.add(Convolution2D(Filter, 3, 3))
model.add(Conv2D(Filter, (3, 3)))
model.add(Activation('relu'))

for i in range(0,Layer):
Filter = random.choice(values)
model.add(Convolution2D(Filter, 3, 3,border_mode='same'))
model.add(Conv2D(Filter, (3, 3),padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.5))
Expand All @@ -180,13 +180,13 @@ def Image_3D_model_CNN(num_classes,shape,kernel_size=(3,3)):
Layer = 3
Filter = random.choice(values)
print(shape)
model.add(Convolution3D(Filter,3,3,1,border_mode='same', input_shape=shape))
model.add(Conv2D(Filter,(3,3),1,padding='same', input_shape=shape))
model.add(Activation('relu'))
model.add(Convolution3D(Filter,3, 3,1, border_mode='same', subsample=(2, 2,1)))
model.add(Conv2D(Filter,(3, 3),1, padding='same', subsample=(2, 2,1)))
model.add(Dropout(0.25))
for i in range(0,Layer):
Filter = random.choice(values)
model.add(Convolution3D(Filter, 3,3,1,subsample = (2,2,1)))
model.add(Conv3D(Filter,(3,3,1),subsample = (2,2,1)))
model.add(Activation('relu'))
model.add(Dense(512,activation='relu'))
model.add(GlobalAveragePooling3D())
Expand Down
21 changes: 13 additions & 8 deletions RMDL/Global.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@
import os
import os.path
global GloVe_DIR
from pathlib import Path
from Download import Download_Glove as GloVe


GloVe_DIR = GloVe.download_and_extract(data='Twitter')
GloVe_file = "glove.6B.100d.txt"
GloVe_DIR = os.path.join(GloVe_DIR, GloVe_file)
GloVe_DIR = ""
GloVe_DIR = ""




if not os.path.isfile(GloVe_DIR):
print("Could not find %s Set GloVe Directory in Global.py ",GloVe)
exit()


MAX_SEQUENCE_LENGTH = 500
MAX_NB_WORDS = 75000
EMBEDDING_DIM = 100 # it could be 50, 100, and 300 please download GLOVE https://nlp.stanford.edu/projects/glove/ and set address of directory in Text_Data_load.py

def setup():
def setup(text=False):
np.set_printoptions(threshold=np.inf)
np.random.seed(7)
if not os.path.exists(".\weights"):
os.makedirs(".\weights")

if text:
GloVe_DIR = GloVe.download_and_extract(data='Twitter')
GloVe_file = "glove.6B.100d.txt"
GloVe_DIR = os.path.join(GloVe_DIR, GloVe_file)
if not os.path.isfile(GloVe_DIR):
print("Could not find %s Set GloVe Directory in Global.py ", GloVe)
exit()
2 changes: 1 addition & 1 deletion RMDL/RMDL_Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

def Image_Classification(X_train, y_train, X_test, y_test, batch_size, shape, sparse_categorical, Random_Deep,
n_epochs):
G.setup()
G.setup(text=False)
y_proba = []

score = []
Expand Down
2 changes: 1 addition & 1 deletion RMDL/RMDL_Text.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
def Text_Classification(X_train, y_train, X_test, y_test, batch_size, sparse_categorical, Random_Deep,
n_epochs):

G.setup()
G.setup(text=True)
X_train_tfidf, X_test_tfidf = txt.loadData(X_train, X_test)
X_train_Embedded, X_test_Embedded, word_index, embeddings_index = txt.loadData_Tokenizer(X_train, X_test)
del X_train
Expand Down
Binary file modified RMDL/__pycache__/BuildModel.cpython-35.pyc
Binary file not shown.
Binary file modified RMDL/__pycache__/Global.cpython-35.pyc
Binary file not shown.
Binary file modified RMDL/__pycache__/RMDL_Image.cpython-35.pyc
Binary file not shown.
Binary file modified RMDL/__pycache__/RMDL_Text.cpython-35.pyc
Binary file not shown.
Binary file added RMDL/__pycache__/__init__.cpython-35.pyc
Binary file not shown.

0 comments on commit a52f008

Please sign in to comment.