Example #1
0
    def post(self, request):
        """
        POST
        Confirma y crea los tfgs devolviendo los errores
        :param request:
        :return :

        """
        try:
            params = utils.get_params(request)
            self.logger.info('INICIO WS - UPLOADFILECONFIRMVIEW POST del usuario: %s con parametros: %s' % (request.user.email if hasattr(request.user, 'email') else request.user.username, params))
            if request.user.has_perm('tfgs.tfg.masivos') or request.user.is_admin:
                model = get_model(params.get('model'))
                load_tfgs = SUBIDAS.get(params.get('model'))()
                resul = load_tfgs.upload_file_confirm(params['list_tfg'])
                if resul['status']:
                    resul_status = status.HTTP_200_OK
                else:
                    resul = dict(message=resul['message'])
                    resul_status = status.HTTP_400_BAD_REQUEST
            else:
                resul = dict(message="Sin privilegios")
                resul_status = status.HTTP_405_METHOD_NOT_ALLOWED
            self.logger.info('FIN WS - UPLOADFILECONFIRMVIEW POST del usuario: %s con resultado: %s' % (request.user.email if hasattr(request.user, 'email') else request.user.username, resul))
            return Response(resul, status=resul_status)
        except Exception as e:
            resul = dict(status=False, message="Error en la llamada")
            self.logger.critical('UPLOADFILECONFIRMVIEW POST: %s %s' % (resul, e))
            return Response(resul, status=status.HTTP_400_BAD_REQUEST)
Example #2
0
def get_forecast(query, url=None):
    """
    Fetches the forecast from the model provider and returns
    the forecast subset to the query domain.
    """
    if url is not None:
        warnings.warn('Forecast was extracted from %s'
                      ' which may be out of date.'
                      % url)
    model = utils.get_model(query['model'])
    fcst = model.fetch(url=url)
    sub_fcst = subset.subset_dataset(fcst, query)
    return sub_fcst
Example #3
0
def main():

    parser = argparse.ArgumentParser(description='Predict the testing set')
    parser.add_argument('--model_type', default='RandomForest')
    parser.add_argument('--test', action='store_true')
    args = parser.parse_args()

    model = get_model(args.model_type, args.test)
    print "Loaded Model: %s" % model

    print "Loading Training Data"
    training = load_training()

    print "Adding new features"
    training = add_features(training)

    print "Running Cross Validaton"
    cross_validate(training, model)
Example #4
0
def main():

    parser = argparse.ArgumentParser(description='Predict the testing set')
    parser.add_argument('--model_type', default='RandomForest')
    parser.add_argument('--test', action='store_true')
    args = parser.parse_args()

    if args.test:
        suffix = 'test'
    else:
        suffix = time.strftime("%d_%m_%Y")

    model = get_model(args.model_type, args.test)
    print "Loaded Model: %s" % model

    print "Loading Training Data"
    training = load_training()

    if not args.test:
        print "Adding new features"
        training = add_features(training)

    print "Training Model"
    classifier = train(training, model)

    print "Saving Classifier"
    output_dir = 'models/classifier_%s' % suffix
    try:
        os.mkdir(output_dir)
    except:
        pass
    joblib.dump(classifier, '%s/%s.pkl' % (output_dir, classifier.__class__.__name__))

    print "Loading testing set"
    testing = load_testing()

    if not args.test:
        print "Adding new features to testing set"
        testing = add_features(testing)

    print "Making predictions on testing set"
    predictions = predict(classifier, testing)
    output_predictions(predictions, threshold=0.7,
                       filename='prediction_%s.csv' % suffix)
Example #5
0
import tensorflow as tf
## Tools
import utils

## Parameters
import params ## you can modify the content of params.py
import preprocess
img_height = params.img_height
img_width = params.img_width
img_channels = params.img_channels


## Test epoch
epoch_ids = [10]
## Load model
model = utils.get_model()

## Preprocess
def img_pre_process(img):
    """
    Processes the image and returns it
    :param img: The image to be processed
    :return: Returns the processed image
    """ 
    # Chop off 1/2 from the top and cut bottom 150px(which contains the head of car)
    ratio = img_height / img_width
    h1, h2 = int(img.shape[0]/2),img.shape[0]-150
    w = (h2-h1) / ratio
    padding = int(round((img.shape[1] - w) / 2))
    img = img[h1:h2, padding:-padding]
    ## Resize the image