Exemplo n.º 1
0
def demo():
	if request.method == 'POST':
		path = request.form['filename']
		file = path
		fileObj = feature_extraction.extractFeatures(file)
		var_sum, means_sum = fileObj.means()
		strObj = "{},{}".format(means_sum, var_sum)
		with open('testData', 'w') as fl:
			fl.write(strObj)
		val = subprocess.check_output(["octave", "classifyMusic.m"])
		val = float(val[657:])
		if(val>=0.5):
			ans = "Genre: Metal"
		else:
			ans = "Genre: Classical"
		return render_template('demo.html', ans=ans)
	return render_template('demo.html',ans="")
Exemplo n.º 2
0
def extractFeaturesImages(imgs):
    # Create a list to append feature vectors to
    imagesFeatures = []
    # Iterate through the list of images
    for img in range(0, len(imgs)):
        # Read in each one by one        
        image = imgs[img]
        
        hog_feat = configParams['use_hog_feat']
        spatial_feat = configParams['use_spatial_feat']
        hist_feat = configParams['use_hist_feat']

        imgFeatures = extractFeatures(image, verbose=False, hog_feat=hog_feat, spatial_feat=spatial_feat, hist_feat=hist_feat)

        imagesFeatures.append(imgFeatures)
    # Return list of feature vectors
    return imagesFeatures 
def search_windows(img, windows, classifier, X_scaler):

    hog_feat = configParams['use_hog_feat']
    spatial_feat = configParams['use_spatial_feat']
    hist_feat = configParams['use_hist_feat']
    
    # Create an empty list to receive positive detection windows
    on_windows = []
    
    count_window = 0
    count_car_window = 0
    # Iterate over all windows in the list
    for window in windows:
        
        # Extract the test window from original image
        window_img = cv2.resize(img[window[0][1]:window[1][1], 
                                  window[0][0]:window[1][0]], 
                              (64, 64))      
        
        # Extract features for that window
        img_features = extractFeatures(window_img, verbose=False, 
                                hog_feat=hog_feat, spatial_feat=spatial_feat, hist_feat=hist_feat)                
        
        # Scale extracted features to be fed to classifier
        test_features = X_scaler.transform(np.array(img_features).reshape(1, -1))
        
        # Predict using your classifier
        prediction = classifier.predict(test_features)
        
        # If positive (prediction == 1) then save the window
        count_window += 1
        if prediction == 1:
            count_car_window += 1
            on_windows.append(window)
            
    
    # Return windows for positive detections
    return on_windows
Exemplo n.º 4
0
import feature_extraction
'''This file is for the generation of the dataSet for classification'''
file = 'classical/classical.00057.wav'
fileObj = feature_extraction.extractFeatures(file)
var_sum, means_sum = fileObj.means()
print("{},{}".format(means_sum, var_sum))

Exemplo n.º 5
0
def SSG_LUGIA(sequence_fasta_file_path=None,
              genome_sequence=None,
              model_name=None,
              model_parameters=None):
    """
    SSG-LUGIA Pipeline
    
    Keyword Arguments:
        sequence_fasta_file_path {string} -- path to the genome sequence fasta file (default: {None})
        genome_sequence {string} -- the actual genome sequence (default: {None})
        model_name {string} -- name of one of the standard models or path to model json file (default: {None})
        model_parameters {dictionary} -- SSG-LUGIA model configuration (default: {None})
    
    Returns:
        list of tuples : list of the tuples containing genomic islands start and end coordinates
    """

    if (sequence_fasta_file_path !=
            None):  # if a genome sequence fasta file has been provided

        genome = loadGenome(sequence_fasta_file_path)

    elif (genome_sequence !=
          None):  # otherwise the genome sequence has been provided

        genome = genome_sequence

    else:  # no genome sequence has been provided

        raise ValueError(
            'Please input either genome sequence of sequence fasta file path')

    if (model_name != None):
        # if a standard model name has been provided
        if (model_name in ['SSG-LUGIA-F', 'SSG-LUGIA-R', 'SSG-LUGIA-P']):
            model = loadModel(model_name)
            # if path to the json file has been provided
        else:
            model = loadModelJson(model_name)

    elif (model_parameters !=
          None):  # a custom model parameter configuration has been provided

        model = model_parameters

    else:  # interactively input the model

        model = inputModel()

    X = extractFeatures(genome, model)  # extracting features

    print()

    print('Detecting Anomalies')

    (yp, ys) = detectAnomalies(X, model)  # Detecting anomalies

    print('Post-Processing')

    ys_mf = medianFiltering(ys, model)  # applying median filter

    yp_mf = binaizeFilteredDistance(ys_mf)  # binarizing the values

    label_pred = inferLabel(yp_mf, len(genome), model)  # infer prediction

    label = trimRegions(label_pred, model)  # eliminate small islands

    genomic_islands = getGenomicIslands(label)  # extract genomic islands

    print('Total Number of Genomic Islands = {}'.format(len(genomic_islands)))

    print('Genomic Islands :')

    for genomic_island in genomic_islands:
        print('{}\t{}'.format(genomic_island[0], genomic_island[1]))

    return genomic_islands  # return the islands