Ejemplo n.º 1
0
def train():
    data = request.get_json()

    df = sessions[data['user']]['df'].frame
    try:
        X,x,Y,y = split(df,data['label'],data['features'])
    except KeyError as e:
        return jsonify(
            dict(
                status=False,
                msg="Please Select Label"
            )
        )

    print (data['traindata']['hyperparams'])

    try:
        model = Train(X=X,x=x,Y=Y,y=y,**data['traindata'])
        train = model.fit()
    except ValueError as e: 
        return jsonify(
            dict(
                status=False,
                msg=str(e)
            )
        )
    

    if train[0]:
        return jsonify(
            dict(
                validation=model.validate(),
                status=True
            )
        )
    else:
        return jsonify(
            dict(
                status=False,
                msg=str(train[1])
            )    
        )
Ejemplo n.º 2
0
class Task(object):
    def __init__(self, config):
        self.train = Train(config)
        self.config = config

    def save(self):
        self.train.save()

    def feedlist(self, wordlist):
        cost = 0
        if len(wordlist) >= 2:
            for i in range(self.config.repeate_times):
                cost += self.train.wordlist(wordlist)
        return cost

    def basic(self, string):
        for i in range(self.config.repeate_times):
            cost = self.train.sentence_str(string)
            print(cost)
        self.train.save()

    def readTxtLine(self, line):
        if len(line) > 20:
            self.basic(line)
Ejemplo n.º 3
0
 def __init__(self, config):
     self.train = Train(config)
     self.config = config
Ejemplo n.º 4
0
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' 

import tensorflow as tf
from dataset.dataset import DataSet
from train.train import Train
from test.test import Test
from model.xception import Xception

'''
    This project uses tensorflow 2.1.0
'''

print('tensorflow version {}'.format(tf.__version__))

ds = DataSet()
xception =  Xception()

# xception.plot_model()
train = Train()
train.train(epochs=3)
Ejemplo n.º 5
0
def init_controller_obj():
    # let's get this party started
    controller_obj = Train()
    return controller_obj
Ejemplo n.º 6
0
from dataset.dataset import Dataset
from util.visualize_dataset import VisualizeDataset
from util.stats import Stats
import tensorflow as tf
from train.darknet.darknet import TDarknet
from train.resnet34.resnet34 import TResNet34
from train.resnet50.resnet50 import TResNet50
from train.inception_v4.inception_v4 import TInception_v4
from test.test_model import TestModel
import numpy as np

print(tf.__version__)

vs = VisualizeDataset()
stats = Stats()
train = Train()

td = TDarknet()
tr34 = TResNet34()
tr50 = TResNet50()
ti = TInception_v4()

dp = DataProcessing()
# dp.process_and_save_data()

ds = Dataset()
# ds.save_trainset_as_npy()

# images, labels = ds.load_testset()
# vs.show_images(images, labels, cols=4, rows=2)
Ejemplo n.º 7
0
# pdb.set_trace()
threshold = torch.tensor(1.0).cuda().detach()
# ####################################################################################################

CLDataset = helper.load_dataset(opt.dataset)
cl_dataset = CLDataset(opt)
cl_dataset.intialization(TaskorClass=False)
labels = cl_dataset.labels
num_class = cl_dataset.num_classes
opt.num_class = num_class

opt.data_size = [
    cl_dataset.get_size(label_index) for label_index in range(opt.num_class)
]
opt.cl_dataset = cl_dataset
train_function = Train(opt)
opt.total_data_train = np.sum(np.array(opt.data_size))
opt.test_set = cl_dataset.test_size
print(opt)

################################################################
#training classes
flag_test = False
for label_index in range(opt.num_class):
    epoch_num = 0
    flag_test = False
    # pdb.set_trace()
    i = 0

    train_function.global_index = label_index
    max_acc = 0
Ejemplo n.º 8
0
    def __run_training__():

        cfg = Configuration()

        # These variable would be parametrized

        GPU = True

        if GPU != True:
            os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
            os.environ["CUDA_VISIBLE_DEVICES"] = ""

        # Input Path

        root_dir = os.path.dirname(os.path.abspath(__file__))

        image_path = cfg.image_path

        json_path = os.path.join(root_dir, cfg.input_filename)

        trainingset = os.path.join(root_dir, 'trainingset')

        Preprocessor.__generate_kijiji_set__(root_dir, image_path, json_path,
                                             trainingset, 'make')

        # --------------------------------------------------------------------------------------------------------------

        image_path = os.path.join(root_dir, 'trainingset')

        data_path = glob(image_path + "/*")

        # Image Segmentation Parameters

        model_path = os.path.expanduser(cfg.model_path)
        assert model_path.endswith('.h5'), 'Keras model must be a .h5 file.'
        anchors_path = os.path.expanduser(cfg.anchors_path)
        classes_path = os.path.expanduser(cfg.classes_path)
        test_path = os.path.expanduser(cfg.test_path)
        output_path = os.path.expanduser(cfg.segmented_output_path)
        json_path = os.path.expanduser(cfg.json_output)

        if not os.path.exists(output_path):
            print('Creating output path {}'.format(output_path))
            os.mkdir(output_path)

        sess = K.get_session()

        class_names = Preprocessor.__return_class_names__(classes_path)

        anchors = Preprocessor.__return_anchors__(anchors_path)

        yolo_model = load_model(model_path)

        # Verify model, anchors, and classes are compatible

        num_classes = len(class_names)

        num_anchors = len(anchors)

        info = 'Mismatch between model and given anchor and class sizes. ' \
               'Specify matching anchors and classes with --anchors_path and --classes_path flags.'

        model_output_channels = yolo_model.layers[-1].output_shape[-1]
        assert model_output_channels == num_anchors * (num_classes + 5), info
        print('{} model, anchors, and classes loaded.'.format(model_path))

        # Check if model is fully convolutional, assuming channel last order.

        model_image_size = yolo_model.layers[0].input_shape[1:3]

        is_fixed_size = model_image_size != (None, None)

        # Generate Colors for drawing bounding boxes

        hsv_tuples, colors = Preprocessor.__generate_colors_for_bounding_boxes__(
            class_names)

        yolo_outputs = yolo_head(yolo_model.output, anchors, len(class_names))

        input_image_shape = K.placeholder(shape=(2, ))
        boxes, scores, classes = yolo_eval(yolo_outputs,
                                           input_image_shape,
                                           score_threshold=cfg.score_threshold,
                                           iou_threshold=cfg.iou_threshold)

        # Load Images from the root folder

        input_images_model_1, all_images, data_path, data_path_with_image_name = Preprocessor.__load_image_data_thumbnails__(
            data_path,
            cfg.compressed_image_height,
            cfg.compressed_image_width,
            cfg.compressed_channel,
            cfg.number_of_categories,
            cfg.number_of_images_per_category,
            root_dir,
            is_fixed_size,
            model_image_size,
            sess,
            yolo_model,
            input_image_shape,
            boxes,
            scores,
            classes,
            cfg.font_path,
            class_names,
            colors,
            output_path,
            json_path,
            test_path,
            True,  # Segmentation Flag
            False,  # Edge-detection Flag
            True,  # Extract object Flag
            False)  # Gray Scale Flag

        input_images_model_2, all_images, data_path, data_path_with_image_name = Preprocessor.__load_image_data_thumbnails__(
            data_path,
            cfg.compressed_image_height,
            cfg.compressed_image_width,
            cfg.compressed_channel,
            cfg.number_of_categories,
            cfg.number_of_images_per_category,
            root_dir,
            is_fixed_size,
            model_image_size,
            sess,
            yolo_model,
            input_image_shape,
            boxes,
            scores,
            classes,
            cfg.font_path,
            class_names,
            colors,
            output_path,
            json_path,
            test_path,
            False,  # Segmentation Flag
            True,  # Edge-detection Flag
            False,  # Extract object Flag
            False)  # Gray Scale Flag

        input_images_model_3, all_images, data_path, data_path_with_image_name = Preprocessor.__load_image_data_thumbnails__(
            data_path,
            cfg.image_height,
            cfg.image_width,
            cfg.channel,
            cfg.number_of_categories,
            cfg.number_of_images_per_category,
            root_dir,
            is_fixed_size,
            model_image_size,
            sess,
            yolo_model,
            input_image_shape,
            boxes,
            scores,
            classes,
            cfg.font_path,
            class_names,
            colors,
            output_path,
            json_path,
            test_path,
            False,  # Segmentation Flag
            False,  # Edge-detection Flag
            False,  # Extract object Flag
            False)  # Gray Scale Flag

        input_shape = [
            cfg.compressed_image_height, cfg.compressed_image_width,
            cfg.compressed_channel
        ]

        input_shape_3 = [cfg.image_height, cfg.image_width, cfg.channel]

        # Model Save Paths

        model_1_save_path = os.path.join(root_dir + cfg.model_1_save)
        model_2_save_path = os.path.join(root_dir + cfg.model_2_save)
        model_3_save_path = os.path.join(root_dir + cfg.model_3_save)

        Preprocessor.__create_output_directories__(model_1_save_path)
        Preprocessor.__create_output_directories__(model_2_save_path)
        Preprocessor.__create_output_directories__(model_3_save_path)

        # Instantiating the training class

        train = Train(input_images_model_1, input_images_model_2,
                      input_images_model_3, input_shape, input_shape_3,
                      cfg.batch_size, cfg.epochs, model_1_save_path,
                      model_2_save_path, model_3_save_path)

        # Output Path

        output_path_model_1 = os.path.join(root_dir + cfg.output_model_1)
        output_path_model_2 = os.path.join(root_dir + cfg.output_model_2)
        output_path_model_3 = os.path.join(root_dir + cfg.output_model_3)

        Preprocessor.__create_output_directories__(output_path_model_1)
        Preprocessor.__create_output_directories__(output_path_model_2)
        Preprocessor.__create_output_directories__(output_path_model_3)

        # FCN Model

        model_1 = train.__train_model_1__()

        # VGG Model

        model_2 = train.__train_model_2__()

        # Inception-v3

        model_3 = train.__train_model_3__()

        features_from_model_1 = Preprocessor.__get_score_model__(
            model_1, input_images_model_1, output_path_model_1)
        features_from_model_2 = Preprocessor.__get_score_model__(
            model_2, input_images_model_2, output_path_model_2)
        features_from_model_3 = Preprocessor.__get_score_model__(
            model_3, input_images_model_3, output_path_model_3)

        print("Output FeatureMap For Model 1 \n")
        print(features_from_model_1.shape)
        print("\n")

        print("Output FeatureMap For Model 2 \n")
        print(features_from_model_2.shape)
        print("\n")

        print("Output FeatureMap For Model 3 \n")
        print(features_from_model_3.shape)
        print("\n")