text
stringlengths 1
93.6k
|
|---|
def get_single_image_x_RGB(self, image_path):
|
image_x = np.zeros((224, 224, 3))
|
binary_mask = np.zeros((28, 28))
|
# RGB
|
image_x_temp = cv2.imread(image_path)
|
#cv2.imwrite('temp.jpg', image_x_temp)
|
image_x = cv2.resize(image_x_temp, (224, 224))
|
# data augment from 'imgaug' --> Add (value=(-40,40), per_channel=True), GammaContrast (gamma=(0.5,1.5))
|
image_x_aug = seq.augment_image(image_x)
|
image_x_temp_gray = cv2.imread(image_path, 0)
|
image_x_temp_gray = cv2.resize(image_x_temp_gray, (28, 28))
|
for i in range(28):
|
for j in range(28):
|
if image_x_temp_gray[i,j]>0:
|
binary_mask[i,j]=1
|
else:
|
binary_mask[i,j]=0
|
return image_x_aug, binary_mask
|
def get_single_image_x(self, image_path):
|
image_x = np.zeros((224, 224, 3))
|
# RGB
|
image_x_temp = cv2.imread(image_path)
|
#cv2.imwrite('temp.jpg', image_x_temp)
|
image_x = cv2.resize(image_x_temp, (224, 224))
|
# data augment from 'imgaug' --> Add (value=(-40,40), per_channel=True), GammaContrast (gamma=(0.5,1.5))
|
image_x_aug = seq.augment_image(image_x)
|
return image_x_aug
|
# <FILESEP>
|
# Arda Mavi
|
import os
|
import sys
|
import tensorflow as tf
|
from keras import backend as K
|
from keras.models import model_from_json
|
def get_keras_model(model_path, weights_path):
|
# Reading model file:
|
with open(model_path, 'r') as model_file:
|
model = model_file.read()
|
# Readed model file to model:
|
model = model_from_json(model)
|
# Loading weights:
|
model.load_weights(weights_path)
|
print('Model Summary:')
|
print(model.summary())
|
return model
|
def keras_to_tf(tf_model_path):
|
saver = tf.train.Saver()
|
with K.get_session() as sess:
|
K.set_learning_phase(0)
|
saver.save(sess, tf_model_path)
|
return True
|
def tf_to_graph(tf_model_path, model_in, model_out, graph_path):
|
os.system('mvNCCompile {0}.meta -in {1} -on {2} -o {3}'.format(tf_model_path, model_in, model_out, graph_path))
|
return True
|
def keras_to_graph(model_path, model_in, model_out, weights_path, graph_path, take_tf_files = False):
|
# Getting Keras Model:
|
keras_model = get_keras_model(model_path, weights_path)
|
# Saving TensorFlow Model from Keras Model:
|
tf_model_path = './TF_Model/tf_model'
|
keras_to_tf(tf_model_path)
|
tf_to_graph(tf_model_path, model_in, model_out, graph_path)
|
if take_tf_files == False:
|
os.system('rm -rf ./TF_Model')
|
if __name__ == '__main__':
|
try:
|
model_path = sys.argv[1]
|
model_in = sys.argv[2]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.