Esempio n. 1
0

# Input and output folders
Train_Image_Dir = os.path.join("Data", "Train", "images") 		# Path to Training images
Train_Label_Dir = os.path.join("Data", "Train", "labels") 		# Path to Training labels
Valid_Image_Dir = os.path.join("Data", "Validation", "images") 		# Path to Validation images 
Valid_Labels_Dir = os.path.join("Data", "Validation", "labels") 	# Path to Validation labels  
logs_dir = os.path.join("logs") 					# Path to log directory
TrainLossTxtFile = os.path.join(logs_dir, "TrainLoss.txt") 		# Path to Training loss record
ValidRecTxtFile = os.path.join(logs_dir, "ValidationRecord.txt")	# Path to Validation record


# Get pretrained model
if not os.path.exists(logs_dir): os.makedirs(logs_dir)
model_path = os.path.join("Model_Zoo", "vgg16.npy") 	# Path to pretrained vgg16 model
CheckVGG16Model.CheckVGG16(model_path) 			# Check vgg16 model, download if not present


# Define Hyperparameters 
NUM_CLASSES = 6 		# Number of classes
Batch_Size = 5			# Number of files per training iteration
Validation_Batch_Size = 5	# Number of files per validation iteration
UseValidationSet = True 	# Validation flag
UseStochasticity = True		# Apply random noise and transformations to training images
learning_rate = 1e-5		# Learning rate for Adam Optimizer
MAX_ITERATION = int(100010) 	# Max  number of training iteration

# Solver for Model
def train(loss_val, var_list):
	optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate, beta1=0.9, beta2=0.999, epsilon=1e-08, use_locking=False)	
	grads = optimizer.compute_gradients(loss_val, var_list=var_list)
Esempio n. 2
0
import TensorflowUtils
import os
import Data_Reader
import OverrlayLabelOnImage as Overlay
import CheckVGG16Model

logs_dir = "logs/"  # "path to logs directory where trained model and information will be stored"
Image_Dir = "Data_Zoo/Steatosis_Datasets/Test_Image/"  # Test image folder
w = 0.6  # weight of overlay on image
Pred_Dir = "Output_Prediction/"  # Library where the output prediction will be written
model_path = "Model_Zoo/vgg16.npy"  # "Path to pretrained vgg16 model for encoder"
NameEnd = ""  # Add this string to the ending of the file name optional
NUM_CLASSES = 3  # Number of classes
#-------------------------------------------------------------------------------------------------------------------------
CheckVGG16Model.CheckVGG16(
    model_path
)  # Check if pretrained vgg16 model avialable and if not try to download it


################################################################################################################################################################################
def main(argv=None):
    # .........................Placeholders for input image and labels........................................................................
    keep_prob = tf.placeholder(tf.float32,
                               name="keep_probabilty")  # Dropout probability
    image = tf.placeholder(
        tf.float32, shape=[None, None, None, 3], name="input_image"
    )  # Input image batch first dimension image number second dimension width third dimension height 4 dimension RGB

    # -------------------------Build Net----------------------------------------------------------------------------------------------
    Net = BuildNetVgg16.BUILD_NET_VGG16(
        vgg16_npy_path=model_path)  # Create class instance for the net
Train_Label_Dir="../data/label"
# Annotetion in png format for train images and validation images (assume the name of the images and annotation images are the same (but annotation is always png format))
UseValidationSet = True
# do you want to use validation set in training
Valid_Image_Dir="../ShelfImages"
# Validation images that will be used to evaluate training
Valid_Labels_Dir="../data/test_label"
#  (the  Labels are in same folder as the training set)
logs_dir= "./logs/"
# "path to logs directory where trained model and information will be stored"
if not os.path.exists(logs_dir): os.makedirs(logs_dir)
model_path="../vgg16.npy"
# "Path to pretrained vgg16 model for encoder"
learning_rate=1e-5 
#Learning rate for Adam Optimizer
CheckVGG16Model.CheckVGG16(model_path)


TrainLossTxtFile=logs_dir+"TrainLoss.txt" #Where train losses will be writen
ValidLossTxtFile=logs_dir+"ValidationLoss.txt"# Where validation losses will be writen
Batch_Size=1 # Number of files per training iteration
Weight_Loss_Rate=5e-4# Weight for the weight decay loss function
MAX_ITERATION = int(90000) # Max  number of training iteration
NUM_CLASSES = 11

def main(argv=None):
    tf.reset_default_graph()
    keep_prob= tf.placeholder(tf.float32, name="keep_probabilty") #Dropout probability
#.........................Placeholders for input image and labels...........................................................................................
    image = tf.placeholder(tf.float32, shape=[None, None, None, 3], name="input_image") #Input image batch first dimension image number second dimension width third dimension height 4 dimension RGB
    GTLabel = tf.placeholder(tf.int32, shape=[None, None, None, 1], name="GTLabel")#Ground truth labels for training