I was trying to run model.fit. I had a data of 5486 rows with target shape (5486,3). I noticed that while running the model.fit, it printed Running on 4489 training samples and 997 validation samples and it started with
Epoch 1/32
5/4856 [>.............................] - ETA: 180s - loss: 0.3286 - accuracy: 0.5406.............
something
Next day I tried another script and while applying fit method it printed
The first code that showed 5/4489 is
`
input_txt = Input(shape=(100,), dtype='int32')
txt = Masking(mask_value=0)(input_txt)
txt = Embedding(len(word_index) + 1, embedding_dim, weights=[embedding_matrix], input_length=max_seq_len, trainable=False)(txt)
txt = Conv1D(32, 5,trainable = False)(txt)
txt = Conv1D(60, 4,trainable = False)(txt)
txt = Conv1D(100, 3,trainable = False)(txt)
text_lstm = Bidirectional(LSTM(30,return_sequences=True,trainable= False))(txt)
text_lstm = Bidirectional(LSTM(30,return_sequences=True,trainable= False))(text_lstm)
text_lstm = Bidirectional(LSTM(30,return_sequences=False,trainable= False))(text_lstm)
lstm = Dense(512, activation='relu')(text_lstm)
lstm = Dropout(0.8)(lstm)
input_img = Input(shape=(224,224,3))
model = VGG16(weights='imagenet', include_top=False)
model.trainable = False
x = model(input_img)
flatten = Flatten()(x)
flatten = Dense(1024, activation='relu')(flatten)
flatten = Dense(512, activation='relu')(flatten)
flatten = Dropout(0.8)(flatten)
merged = concatenate([lstm,flatten], axis=1)
dense = Dense(1024, activation='relu')(merged)
dense = Dropout(0.6)(dense)
dense = Dense(512, activation='relu')(dense)
dense = Dense(256, activation='relu')(dense)
dense = Dense(128, activation='relu')(dense)
dense = Dense(3, activation='softmax')(dense)
model = Model(inputs=(input_img,input_txt), outputs=dense)
model.compile(loss='categorical_crossentropy',optimizer=keras.optimizers.Adam(lr=2e-5),metrics=["accuracy"])
X_trn = [image_data,text_data]
y_trn = labels
model.fit(X_trn,y_trn,validation_split=0.2,epochs = 32, batch_size = 64)
`
Epoch 1/32
5/151 [>.............................] - ETA: 40s - loss: 0.0286 - accuracy: 0.5406.............
And the code that gave the above verbose was
`
vgg = VGG19(weights='imagenet',include_top=False)
vgg.trainable = False
img_in = Input(shape=(224,224,3),dtype = 'int32')
img = vgg(img_in)
img = Flatten()(img)
img = Dense(1024,activation='sigmoid')(img)
img = Dense(512,activation='sigmoid')(img)
img = Dense(64,activation='relu')(img)
img = Dense(32,activation = 'relu')(img)
out = Dense(3,activation='softmax')(img)
model = Model(inputs = [img_in],outputs=out)
model.compile(loss='categorical_crossentropy',
optimizer=Adam(lr=2e-5),
# optimizer=optimizers.RMSprop(),
metrics=["accuracy"]
model.fit(x=images_data[4856:],y= data_labels[4856:],validation_data=(images_data[:4856], data_labels[:4856]),batch_size =64, epochs=32)
`
I noticed that data drop from 4489 to 101. I tried checking everything, but didn't got anywhere. Someone please explain what happened.
Thanks in advance
Related
How to fix the error "Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 150528 but received input with shape [224, 672]".
I'd problem to build sequantial model. Hope you all will help me on this time.
def decode_csv(csv_row):
record_defaults = ["path", "flower"]
filename, label_string = tf.io.decode_csv(csv_row, record_defaults)
img = read_and_decode(filename, [IMG_HEIGHT, IMG_WIDTH])
return img, label_string
train_dataset (tf.data.TextLineDataset("/home/pi/Downloads/ml_code/train_set.csv").map(decode_csv)).take(500)
eval_dataset = (tf.data.TextLineDataset("/home/pi/Downloads/ml_code/eval_set.csv").map(decode_csv)).take(50)
model =tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape = (IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS)),
tf.keras.layers.Dense(len(CLASS_NAME), activation = "softmax")
])
model.compile(optimizer="adam",
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = False),
metrics = ['accuracy'])
model.summary()
tf.keras.utils.plot_model(model, show_shapes = True, show_layer_names = False, to_file = "model.jpg")
history = model.fit(train_dataset, validation_data = eval_dataset, epochs = 10)
model.save("first")
json.dump(history.history, open("First_History", "w"))
Try something like this:
import pandas as pd
# Create dummy data
tf.keras.utils.save_img('image1.png', tf.random.normal((64, 64, 3)))
tf.keras.utils.save_img('image2.png', tf.random.normal((64, 64, 3)))
tf.keras.utils.save_img('image3.png', tf.random.normal((64, 64, 3)))
tf.keras.utils.save_img('image4.png', tf.random.normal((64, 64, 3)))
tf.keras.utils.save_img('image5.png', tf.random.normal((64, 64, 3)))
df = pd.DataFrame(data= {'path': ['/content/image1.png', '/content/image2.png', '/content/image3.png', '/content/image4.png', '/content/image5.png'],
'label': ['0', '1', '2', '3', '2']})
df.to_csv('data.csv', index=False)
Preprocess data and train:
import tensorflow as tf
def decode_csv(csv_row):
record_defaults = ["path", "label"]
filename, label_string = tf.io.decode_csv(csv_row, record_defaults)
img = tf.io.decode_png(tf.io.read_file(filename), channels=3)
return img, tf.strings.to_number(label_string, out_type=tf.int32)
# Skip header row.
train_dataset = tf.data.TextLineDataset("/content/data.csv").skip(1).map(decode_csv).batch(2)
model =tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape = (64, 64, 3)),
tf.keras.layers.Dense(4, activation = "softmax")
])
model.compile(optimizer="adam",
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = False),
metrics = ['accuracy'])
model.summary()
tf.keras.utils.plot_model(model, show_shapes = True, show_layer_names = False, to_file = "model.jpg")
history = model.fit(train_dataset, epochs = 2)
model.save("first")
Model: "sequential_2"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
flatten_2 (Flatten) (None, 12288) 0
dense_2 (Dense) (None, 4) 49156
=================================================================
Total params: 49,156
Trainable params: 49,156
Non-trainable params: 0
_________________________________________________________________
Epoch 1/2
3/3 [==============================] - 1s 62ms/step - loss: 623.7551 - accuracy: 0.4000
Epoch 2/2
3/3 [==============================] - 0s 7ms/step - loss: 1710.6586 - accuracy: 0.2000
INFO:tensorflow:Assets written to: first/assets
My Final Fix Code is here:
def read_and_decode(filename, reshape_dims):
img = tf.io.read_file(filename)
# Range [0, 255]
img = tf.image.decode_jpeg(img, channels = 3)
#convert into range[0, 1] for ml flexible
img = tf.image.convert_image_dtype(img, tf.float32)
return img
def decode_csv(csv_row):
record_defaults = ["path", "flower"]
filenames, label_string = tf.io.decode_csv(csv_row, record_defaults, field_delim = ",")
img = read_and_decode(filenames, [IMG_HEIGHT, IMG_WIDTH])
return img, tf.argmax(tf.cast(label_string == CLASS_NAME, tf.int32))
train_dataset = tf.data.TextLineDataset("/home/pi/Downloads/ml_code/train_set.csv").skip(1).map(decode_csv).batch(2)
eval_dataset = tf.data.TextLineDataset("/home/pi/Downloads/ml_code/eval_set.csv").skip(1).map(decode_csv).batch(2)
model =tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape = (IMG_HEIGHT, IMG_WIDTH, 3)),
tf.keras.layers.Dense(len(CLASS_NAME), activation = "softmax")
])
model.compile(optimizer="adam",
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = False),
metrics = ['accuracy'])
model.summary()
tf.keras.utils.plot_model(model, show_shapes = True, show_layer_names = False, to_file = "model.jpg")
history = model.fit(train_dataset, validation_data = eval_dataset, epochs = 2)
model.save("first")
json.dump(history.history, open("First_History", "w"))
All credits should go to AloneTogether, Thanks for your help ^_^.
I am training a model for text sentiment classification with CNN. In it, the validation accuracy is initially more than training accuracy and then it decreases. Is this behavior acceptable? If not then what can be the reason and how to solve it?
My model:
class hyper():
def __init__(self,embedding_dim,filter_sizes,num_filters,dropout_prob,hidden_dims,batch_size,num_epochs):
# Model Hyperparameters
self.embedding_dim = embedding_dim
self.filter_sizes = filter_sizes
self.num_filters = num_filters
self.dropout_prob = dropout_prob
self.hidden_dims = hidden_dims
# Training parameters
self.batch_size = batch_size
self.num_epochs = num_epochs
class prep_hyper():
def __init__(self,sequenceLength,max_words):
# Prepossessing parameters
self.sequenceLength = sequenceLength
self.max_words = max_words
m_hyper=hyper(embedding_dim=embed_dim,filter_sizes=(3,4,5,6,8),num_filters=80,dropout_prob=(0.2,0.5),
hidden_dims=50,batch_size=128,num_epochs= 30)
pr_hyper = prep_hyper(sequenceLength=sequence_length,max_words=vocab_size)
model architecture:
def build_model(pr_hyper,m_hyper):
# Convolutional block
model_input = Input(shape=(pr_hyper.sequenceLength))
# use a random embedding for the text
x = Embedding(pr_hyper.max_words, m_hyper.embedding_dim,weights=[emb],trainable=False)(model_input)
# x = SpatialDropout1D(m_hyper.dropout_prob[0])(x)
conv_kern_reg = regularizers.l2(0.0001)
conv_bias_reg = regularizers.l2(0.0001)
conv_blocks = []
for sz in m_hyper.filter_sizes:
conv = Convolution1D(filters=m_hyper.num_filters,
kernel_size=sz,
# padding="same",
activation="relu",
strides=1,
kernel_regularizer=conv_kern_reg,
bias_regularizer=conv_bias_reg
)(x)
conv = GlobalMaxPooling1D()(conv)
conv_blocks.append(conv)
# merge
x = Concatenate()(conv_blocks) if len(conv_blocks) > 1 else conv_blocks[0]
x = Dense(m_hyper.hidden_dims, activation="relu")(x)
x = Dropout(m_hyper.dropout_prob[1])(x)
x = Dense(100, activation="relu")(x)
x = Dropout(m_hyper.dropout_prob[1])(x)
model_output = Dense(3, activation="softmax")(x)
model = Model(model_input, model_output)
model.compile(loss="categorical_crossentropy", optimizer=keras.optimizers.Adam(learning_rate=0.00005), metrics=["accuracy"]) #categorical_crossentropy
print(model.summary())
tf.keras.utils.plot_model(model, show_shapes=True)#, to_file='multichannel.png')
return model
INITIAL EPOCHS:
There are several reasons that this happens, like, the dropout layers is disabled during validation. For more information I would suggest you to see this
that describes several possible reasons that this happens.
I am trying to create a model to predict if the text is a work reference or work description:
code:
X = df.v2
Y = df.v1
le = LabelEncoder()
Y = le.fit_transform(Y)
Y = Y.reshape(-1,1)
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.15)
max_words = 1000
max_len = 150
tok = Tokenizer(num_words=max_words)
tok.fit_on_texts(X_train)
sequences = tok.texts_to_sequences(X_train)
sequences_matrix = sequence.pad_sequences(sequences,maxlen=max_len)
def RNN():
inputs = Input(name='inputs',shape=[max_len])
layer = Embedding(max_words,50,input_length=max_len)(inputs)
layer = LSTM(64)(layer)
layer = Dense(256,name='FC1')(layer)
layer = Activation('relu')(layer)
layer = Dropout(0.5)(layer)
layer = Dense(1,name='out_layer')(layer)
layer = Activation('sigmoid')(layer)
model = Model(inputs=inputs,outputs=layer)
return model
model = RNN()
model.summary()
model.compile(loss='binary_crossentropy',optimizer=RMSprop(),metrics=['accuracy'])
model.fit(sequences_matrix,Y_train,batch_size=128,epochs=10,
validation_split=0.2,callbacks=[EarlyStopping(monitor='val_loss',min_delta=0.0001)])
test_sequences = tok.texts_to_sequences(X_test)
test_sequences_matrix = sequence.pad_sequences(test_sequences,maxlen=max_len)
accr = model.evaluate(test_sequences_matrix,Y_test)
print('Test set\n Loss: {:0.3f}\n Accuracy: {:0.3f}'.format(accr[0],accr[1]))
sample_texts = ["this is sample input"]
txts = tok.texts_to_sequences(sample_texts)
txts = sequence.pad_sequences(txts, maxlen=max_len)
preds = model.predict(txts)
print(preds)
Results:
Loss: 0.049
Accuracy: 0.980
preds = 0.95173115
My question: how do I output the label instead of score? Can anyone point me in the right direction, please?
SOURCE: https://www.kaggle.com/kredy10/simple-lstm-for-text-classification
I have Keras model shown below where I'm trying to merge an image input with a feature vector of numerical values, but having the following error:
ValueError: Input 0 is incompatible with layer flatten_2: expected
min_ndim=3, found ndim=2
which occurs on the following statement:
value_model.add(Flatten(input_shape=(12,)))
Any ideas on how I can solve the issue?
image_input = Input((512, 512, 1))
vector_input = Input((12,))
image_model = Sequential()
image_model.add(Convolution2D(32,8,8, subsample=(4,4), input_shape=(512,512,1)))
image_model.add(Activation('relu'))
image_model.add(Convolution2D(64,4,4, subsample=(2,2)))
image_model.add(Activation('relu'))
image_model.add(Convolution2D(64,3,3, subsample=(1,1)))
image_model.add(Activation('relu'))
image_model.add(Flatten())
image_model.add(Dense(512))
image_model.add(Activation('relu'))
value_model = Sequential()
value_model.add(Flatten(input_shape=(12,)))
value_model.add(Dense(16))
value_model.add(Activation('relu'))
value_model.add(Dense(16))
value_model.add(Activation('relu'))
value_model.add(Dense(16))
value_model.add(Activation('relu'))
merged = Concatenate([image_model, value_model])
final_model = Sequential()
final_model.add(merged)
final_model.add(Dense(1, activation='sigmoid'))
model = Model(inputs=[image_input, vector_input], outputs=output)
model.compile(loss='binary_crossentropy', optimizer='adam',metrics=['acc'])
model.fit([images, features], y, epochs=5)
EDIT-1
This is the full script:
from keras.layers import Input, Concatenate, Conv2D, Flatten, Dense, Convolution2D, Activation
from keras.models import Model, Sequential
import pandas as pd
import numpy as np
import cv2
import os
def label_img(img):
word_label = img.split('.')[-3]
if word_label == 'r':
return 1
elif word_label == 'i':
return 0
train_directory = '/train'
images = []
y = []
dataset = pd.read_csv('results.csv')
dataset = dataset[[ 'first_value',
'second_value']]
features = dataset.iloc[:,0:12].values
for root, dirs, files in os.walk(train_directory):
for file in files:
image = cv2.imread(root + '/' + file)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.resize(image,(512,512),interpolation=cv2.INTER_AREA)
image = image/255
images.append(image)
label = label_img(file)
y.append(label)
images = np.asarray(images)
images = images.reshape((-1,512,512,1))
image_input = Input((512, 512, 1))
vector_input = Input((12,))
image_model = Sequential()
image_model.add(Convolution2D(32,8,8, subsample=(4,4), input_shape=(512,512,1)))
image_model.add(Activation('relu'))
image_model.add(Convolution2D(64,4,4, subsample=(2,2)))
image_model.add(Activation('relu'))
image_model.add(Convolution2D(64,3,3, subsample=(1,1)))
image_model.add(Activation('relu'))
image_model.add(Flatten())
image_model.add(Dense(512))
image_model.add(Activation('relu'))
value_model = Sequential()
#value_model.add(Flatten(input_shape=(12,)))
value_model.add(Dense(16))
value_model.add(Activation('relu'))
value_model.add(Dense(16))
value_model.add(Activation('relu'))
value_model.add(Dense(16))
value_model.add(Activation('relu'))
merged = Concatenate([image_model, value_model])
final_model = Sequential()
final_model.add(merged)
final_model.add(Dense(1, activation='sigmoid'))
model = Model(inputs=[image_input, vector_input], outputs=output)
model.compile(loss='binary_crossentropy', optimizer='adam',metrics=['acc'])
model.fit([images, features], y, epochs=5)
EDIT-2
When I did the following:
output = final_model.add(Dense(1, activation='sigmoid'))
I still received the same error.
You can change your code to reflect new Keras 2 API like shown below. In your code you are trying a mixed approach of older keras API and Keras 2 API.
I also recommend to use new Conv2D layer instead of Convolution2D layer along with Keras 2 API. The subsample argument is now called strides in Conv2D
image_input = Input((512, 512, 1))
vector_input = Input((12,))
image_model = Conv2D(32,(8,8), strides=(4,4))(image_input)
image_model = Activation('relu')(image_model)
image_model = Conv2D(64,(4,4), strides=(2,2))(image_model)
image_model = Activation('relu')(image_model)
image_model = Conv2D(64,(3,3), strides=(1,1))(image_model)
image_model = Activation('relu')(image_model)
image_model = Flatten()(image_model)
image_model = Dense(512)(image_model)
image_model = Activation('relu')(image_model)
value_model = Dense(16)(vector_input)
value_model = Activation('relu')(value_model)
value_model = Dense(16)(value_model)
value_model = Activation('relu')(value_model)
value_model = Dense(16)(value_model)
value_model = Activation('relu')(value_model)
merged = concatenate([image_model, value_model])
output = Dense(1, activation='sigmoid')(merged)
model = Model(inputs=[image_input, vector_input], outputs=output)
model.compile(loss='binary_crossentropy', optimizer='adam')
Consider a toy dataset,
I = np.random.rand(100, 512, 512, 1)
V = np.random.rand(100, 12, )
y = np.random.rand(100, 1, )
Training,
model.fit([I, V], y, epochs=10, verbose=1)
Epoch 1/10
100/100 [==============================] - 9s 85ms/step - loss: 3.4615
Epoch 2/10
32/100 [========>.....................] - ETA: 4s - loss: 0.9696
I am training my own model using Tensorflow. However, I got some trouble when I change my activation function from Relu to Selu.
This is what happened. Learning curve drops accidentally and I have no idea about what's going on.
my learning curve
like this.
For what I have known, Selu can prevent overfitting, so I try to implement it in my model. Is there any tips, or any condition when I want to use Selu?
This is my code:
this is the place where I change my activation function
-----
def conv2d_maxpool(x_tensor, conv_num_outputs, conv_ksize, conv_strides, pool_ksize, pool_strides, layer_name):
conv_layer = tf.layers.conv2d(x_tensor, conv_num_outputs, kernel_size=conv_ksize, strides=conv_strides, activation=tf.nn.selu, name = layer_name)
conv_layer = tf.layers.max_pooling2d(conv_layer, pool_size=pool_ksize, strides=pool_strides)
return conv_layer
-----
graph
tf.reset_default_graph()
#### placeholder ####
input_img = tf.placeholder(dtype=tf.float32, shape=(None, img_size, img_size, 3))
y_true = tf.placeholder(dtype=tf.float32, shape=(None, num_class))
keep_prob = tf.placeholder(tf.float32, name="keep_prob")
lr_in = tf.placeholder(dtype = tf.float32, name = 'learning_rate')
conv_ksize = (3,3)
conv_strides = (1,1)
pool_ksize = (2,2)
pool_strides = (2,2)
n_filters_1 = 32
n_filters_2 = 64
n_filters_3 = 128
n_filters_4 = 256
onebyone_ksize = (1,1)
#CNN
conv_1 = conv2d_maxpool(input_img, n_filters_1, conv_ksize, conv_strides, pool_ksize, pool_strides, layer_name = "conv1")
# conv_1 = tf.layers.conv2d(conv_1, conv_num_outputs, kernel_size=conv_ksize, strides=conv_strides, activation=tf.nn.relu)
# conv_1_norm = tf.layers.batch_normalization(conv_1, name = "batch_norm1")
# conv_1_dropout = tf.layers.dropout(conv_1_norm, rate = keep_prob, training = True, name = "dropout1")
conv_2 = conv2d_maxpool(conv_1, n_filters_2, conv_ksize, conv_strides, pool_ksize, pool_strides, layer_name = "conv2")
# conv_2_norm = tf.layers.batch_normalization(conv_2)
conv_3 = conv2d_maxpool(conv_2, n_filters_3, conv_ksize, conv_strides, pool_ksize, pool_strides, layer_name = "conv3")
# conv_3_norm = tf.layers.batch_normalization(conv_3, name = "batch_norm3")
# conv_3_dropout = tf.layers.dropout(conv_3_norm, rate = keep_prob, training = True, name = "dropout3")
conv_4 = conv2d_maxpool(conv_3, n_filters_4, conv_ksize, conv_strides, pool_ksize, pool_strides, layer_name = "conv4")
flatten = tf.layers.flatten(conv_4)
fc1 = tf.layers.dense(flatten, 256, activation = tf.nn.relu)
out = tf.layers.dense(fc1, 6, activation=None, name= "logits") #logit
predict = tf.nn.softmax(out)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = out, labels = y_true))
optimizer = tf.train.AdamOptimizer(lr).minimize(cost)
##accuracy
correct_pred = tf.equal(tf.argmax(out, 1), tf.argmax(y_true, 1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32), name='accuracy')
Training
#history/record
train_loss, train_acc = [], []
valid_loss, valid_acc = [], []
update_per_epoch = int(np.floor(X_train.shape[0] / batch_size))
## early stopping and learning rate congig
es_patience = 10
es_n = 0
lr_patience = 3
lr_n = 0
save_model_path = './save'
saver = tf.train.Saver()
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
# Initializing the variables
batch_gen = img_gen.flow(generator_input(X_train), y_train, batch_size = 32)
val_batch_gen = img_gen.flow(generator_input(X_valid), y_valid, batch_size = len(X_valid))
for i in range(epoch):
epoch_loss = 0
epoch_acc = 0
for j in range(update_per_epoch):
image, label = next(batch_gen)
_, this_loss, this_acc = sess.run([optimizer, cost, accuracy], feed_dict={
input_img : image,
y_true : label,
lr_in: lr,
keep_prob : keep_probability
})
epoch_loss += this_loss
epoch_acc += this_acc
## end of epoch
epoch_loss /= update_per_epoch
epoch_acc /= update_per_epoch
train_loss.append(epoch_loss)
train_acc.append(epoch_acc)
print('Epoch {:>2} Loss: {:>4.4f} Training Accuracy: {:.6f}'.format(i + 1, epoch_loss, epoch_acc))
valid_image, valid_label = next(val_batch_gen)
valid_this_loss, valid_this_acc = sess.run([cost, accuracy], feed_dict = {
input_img: valid_image,
y_true: valid_label,
lr_in: lr,
keep_prob: 1.
})
valid_loss.append(valid_this_loss)
valid_acc.append(valid_this_acc)
print('Epoch {:>2} Loss: {:>4.4f} Validation Accuracy: {:.6f}'.format(i + 1,valid_this_loss, valid_this_acc))
# early stop
if valid_this_loss > np.min(valid_loss):
es_n += 1
lr_n += 1
else:
es_n = 0
lr_n = 0
saver.save(sess, os.path.join(os.getcwd(), 'bestsession.ckpt'))
# early stop
if es_n >= es_patience:
print("-----------early stopping-------------")
break
# adaptive learning rate
if lr_n >= lr_patience:
lr *= lr_decay_rate
lr_n = 0
print("-----------adjust learning rate------------")
# Save Model
save_path = saver.save(sess, save_model_path)
print('-----model save ------')
----------- 18/09/07------------
I can always reproduce the same result.
And this is my code, I wrote it in Jupyter. But sorry I can't upload the training data:
https://drive.google.com/open?id=1uUE32KrNmWnhLbV8z-fyHSMu6zGCCG_e