コード例 #1
0
def main(csv_file):
    # Check input file whether being csv.
    if csv_file.split(".")[-1] != "csv":
        print("Input file is not a csv file.")
        return

    #run_translator("data/es-en.csv")
    #calculate_ribes("result/es-en.csv")
    calculate_features("result/es-en.csv")

    print("Success on executing main!!")
コード例 #2
0
def get_features(data, params=Constants()):
    excluded = 0
    overall = 0
    IPy = False
    if "IPython.display" in sys.modules.keys():
        from IPython.display import clear_output
        IPy = True
    for di, d in enumerate(data):
        if di % 100 == 0:
            if IPy:
                clear_output()
            print(di, ' out of ', len(data))
        st_features = calc_feat.calculate_features(d['signal'],
                                                   params.framerate, None).T
        x = []
        y = []
        for f in st_features:
            overall += 1
            if f[1] > 1.e-4:
                x.append(f)
                y.append(d['emotion'])
            else:
                excluded += 1
        x = np.array(x, dtype=float)
        y = np.array(y)
        save_sample(x, y, params.path_to_features + d['id'] + '.csv')
    return overall, excluded
コード例 #3
0
def emotion_predict(path):
    wav = open_wav(path)
    (nchannels, sampwidth, framerate, nframes, comptype,
     compname), samples = wav
    duration = nframes / framerate

    print('channel count', nchannels)
    left = samples[0::nchannels]
    print('left', left)
    print('left shape', left.shape)
    # right = samples[1::nchannels]
    # left_audio = left[int(start * framerate):int(end * framerate)]
    st_features = cf.calculate_features(left, framerate, None).T

    x = []
    for f in st_features:
        if f[1] > 1.e-4:
            x.append(f)
    x = np.array(x, dtype=float)
    tx = []
    tx.append(np.array(x, dtype=float))
    tx = np.array(tx, dtype=float)
    tx = pad_sequence(tx, 32)

    model = load_model('iemocap_acc0.561715.h5', compile=False)
    available_emotions = ['生气', '激动', '紧张', '悲伤']
    predictResult = model.predict(tx)
    #emotion = available_emotions[np.argmax(predictResult)]
    #prob = predictResult[0][np.argmax(predictResult)]

    return predictResult[0].tolist()
コード例 #4
0
def driver_trips(driver_number):
    number_of_trips = 200
    df = np.zeros((200, 18), dtype=np.float32)
    for i in range(1, number_of_trips + 1, 1):
        filename = 'drivers/' + str(driver_number) + '/' + str(i) + '.csv'
        fdict = calculate_features.calculate_features(filename)
        df[i - 1] = fdict
    #for col in range(df.shape[1]):
    #df[:,col] = (df[:,col] - df[:,col].mean())/(df[:,col].max() - df[:,col].min())
    return df
コード例 #5
0
def train_model(images, mask_list, k_size, probability):
    """
    Train model with list of images
    """
    logging.info('Calculating, normalizing feature vectors for %d image(s)',
                 len(images))
    vectors_list = [
        calculate_features(x.image, x.fov_mask, mask_list, k_size)
        for x in images
    ]
    truth_list = [x.truth for x in images]
    logging.info('Training model with %d image(s)', len(images))
    svm.train(vectors_list, truth_list,
              probability)  # Train SVM, lengthy process
コード例 #6
0
def get_features(data, save=True, path='samples/l_', mode='calculate'):
    if mode == 'calculate':
        for di, d in enumerate(data):
            print di, ' out of ', len(data)
            st_features = cf.calculate_features(d['left'], None).T
            x = []
            y = []
            for f in st_features:
                if f[1] > 1.e-4:
                    x.append(f)
                    y.append(d['emotion'])
            x = np.array(x, dtype=float)
            y = np.array(y)
            if save:
                save_sample(x, y, path + d['id'] + '.csv')
        return x, y
コード例 #7
0
def get_features(data, save=True, path='samples/l_', mode='calculate'):
  if mode == 'calculate':
    for di, d in enumerate(data):
      print di, ' out of ', len(data)
      st_features = cf.calculate_features(d['left'], None).T
      x = []
      y = []
      for f in st_features:
        if f[1] > 1.e-4:
          x.append(f)
          y.append(d['emotion'])
      x = np.array(x, dtype=float)
      y = np.array(y)
      if save:
        save_sample(x, y, path + d['id'] + '.csv')
    return x, y
コード例 #8
0
def get_features(data, save=True, path=path_to_samples):
  failed_samples = []
  for di, d in enumerate(data):
    if di%1000 == 0: 
      print di, ' out of ', len(data)
    st_features = cf.calculate_features(d['signal'], framerate, None).T
    x = []
    y = []
    for f in st_features:
      if f[1] > 1.e-4:
        x.append(f)
        y.append(d['emotion'])
    x = np.array(x, dtype=float)
    y = np.array(y)

    if save:
      save_sample(x, y, path + d['id'] + '.csv')
  return x, y
コード例 #9
0
def get_features(data, save=True, path=path_to_samples):
    failed_samples = []
    for di, d in enumerate(data):
        if di % 1000 == 0:
            print di, ' out of ', len(data)
        st_features = cf.calculate_features(d['signal'], framerate, None).T
        x = []
        y = []
        for f in st_features:
            if f[1] > 1.e-4:
                x.append(f)
                y.append(d['emotion'])
        x = np.array(x, dtype=float)
        y = np.array(y)

        if save:
            save_sample(x, y, path + d['id'] + '.csv')
    return x, y
コード例 #10
0
def classify_image(images, mask_list, k_size, save, display):
    """
    Classify pixels of a single image
    """
    if len(images) > 1:
        raise ValueError('Only one image can be classified at once')
    logging.info('Calculating, normalizing feature vectors for image')
    image = images[0]  # First and only member
    vectors = calculate_features(image.image, image.fov_mask, mask_list,
                                 k_size)
    logging.info('Classifying image pixels')
    probabilities, prediction = svm.classify(vectors)
    svm.assess(image.truth, prediction)
    svm.plot_roc(image.truth, probabilities)

    if save:
        image_utils.save_image(prediction, 'prediction.png')
        logging.info('Saved classified image')
    if display:
        image_utils.display_image(prediction)
        logging.info('Displaying classified image')