Пример #1
0
    def loadKeys(self):
        if not os.path.exists("keys"):
            os.mkdir("keys")
            return

        files = get_all_files("keys/")

        for key in files:
            key_name = self.loadKeyFromFile(f"keys/{key}")

            self.gui.keyBox.insert(0, key_name)
Пример #2
0
def calculate():
    d = sys.argv[1]
    files = util.get_all_files(d)
    files_count = float(len(files))

    avg = 0
    for f in files:
        h = open(f[0] + f[1])

        body = h.read()
        avg += average(body)

        h.close()

    avg /= files_count

    print 'Average word length: ' + str(avg)
Пример #3
0
def main():
    argument_parser = argparse.ArgumentParser()
    argument_parser.add_argument('--input-dir')
    argument_parser.add_argument('--output-dir', default='data')
    argument_parser.add_argument('--train-size', default=0.7, type=float)
    args = argument_parser.parse_args()

    sub_dirs = get_subdirs(args.input_dir)

    for class_dir in sub_dirs:
        file_paths = get_all_files(class_dir)

        # Remove the folder above the dataset
        class_dir = class_dir.split('/')[-1]
        train_files, test_files = train_test_split(file_paths,
                                                   train_size=args.train_size)
        move_files(train_files, args.output_dir + '/train/' + class_dir)
        move_files(test_files, args.output_dir + '/test/' + class_dir)
Пример #4
0
def load_all(styles, batch_size, time_steps):
    """
    Loads all MIDI files as a piano roll.
    (For Keras)
    """
    note_data = []
    beat_data = []
    style_data = []

    note_target = []

    # TODO: Can speed this up with better parallel loading. Order gaurentee.
    styles = [y for x in styles for y in x]

    for style_id, style in enumerate(styles):
        style_hot = one_hot(style_id, NUM_STYLES)
        # Parallel process all files into a list of music sequences
        seqs = Parallel(n_jobs=multiprocessing.cpu_count(),
                        backend='threading')(delayed(load_midi)(f)
                                             for f in get_all_files([style]))

        for seq in seqs:
            if len(seq) >= time_steps:
                # Clamp MIDI to note range
                seq = clamp_midi(seq)
                # Create training data and labels
                train_data, label_data = stagger(seq, time_steps)
                note_data += train_data
                note_target += label_data


#                 beats = [compute_beat(i, NOTES_PER_BAR) for i in range(len(seq))]
#                 beat_data += stagger(beats, time_steps)[0]

    note_data = np.array(note_data)
    #     beat_data = np.array(beat_data)
    note_target = np.array(note_target)

    #note_data[:,:,:,2] = 0 #note_data[:,:,:,0]
    #note_target[:,:,:,2] = 0 #note_target[:,:,:,0]

    return note_data, note_target,
Пример #5
0
def main_augumented_img(file_path, aug_img_folder):

    image_paths = util.get_all_files(file_path, reg='.npy')

    count = 0
    total_img = len(image_paths)

    for i in range(total_img):
        print('processed images ratio: ' + str(int(i * 100 / total_img)) + "%")
        c = gen_augumented_img(image_paths[i],
                               aug_img_folder,
                               size_label=128,
                               stride=64)
        count += c

    print('total num of images: ' + str(i))
    print('total num of <quad, bayer/rgb> pairs after augumentation: ' +
          str(count))

    pass
Пример #6
0
    def init_environment(self):

        if os.path.exists(self.pages_folder_path):
            util.remove_folder_contents(self.pages_folder_path)
        os.makedirs(self.pages_folder_path)

        if os.path.exists(self.train_path):
            util.remove_folder_contents(self.train_path)
        os.makedirs(self.train_path)

        if os.path.exists(self.valid_path):
            util.remove_folder_contents(self.valid_path)
        os.makedirs(self.valid_path)

        if os.path.exists(self.test_path):
            util.remove_folder_contents(self.test_path)
        os.makedirs(self.test_path)

        if not os.path.exists(self.urls_folder_path):
            print('pls provide url files in a folder named urls')
            return

        self.urls_file_names = util.get_all_files(self.urls_folder_path)
        logger.info('init environment')
Пример #7
0
def unpack_works(config):
    cv_folder = config['working'] + config['cv dir']
    all_cv = util.get_all_files(cv_folder)
    works = unpack_works_from_all_cv(all_cv)
    return works
Пример #8
0
                        ids2names[idn] = set()
                    ids2names[idn].add(name)
                    if (debug) and (len(ids2names[idn]) > 1):
                        print('{0} cant write their name!'.format(name))

                except ValueError:
                    print('discarded entry!')

    return names2ids, ids2names


if __name__ == '__main__':
    config = util.load_config(sys.argv[1])
    if sys.argv[2] == 'CV':
        cv_folder = config['working'] + config['cv dir']
        all_cv = util.get_all_files(cv_folder)
        names = get_name_frequency(all_cv, debug=True)
        print('---')
        print(names)
        print('...')
    elif sys.argv[2] == 'ID':
        source = cfs.get_input(config)
        names2ids, ids2names = relate_names_and_ids(source, debug=True)
        print('--- # Name -> #Ids')
        for name in names2ids:
            print('{0}: {1}'.format(name, len(names2ids[name])))
        print('--- # Id -> #names')
        for idn in ids2names:
            print('{0}: {1}'.format(idn, len(ids2names[idn])))
        print('...')