def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input_dir',
        type=str,
        default='./out',
        help='Directory path to the npy files. (default: %(default)s)')
    parser.add_argument(
        '--graph_dir',
        type=str,
        default='./graphs',
        help='Directory path to the graphs output. (default: %(default)s)')
    parser.add_argument('--model_path',
                        type=str,
                        required=True,
                        help='Path of the model. (required)')
    parser.add_argument(
        '--normalize',
        action='store_true',
        help=
        'Boolean flag activating normalization of the confusion matrix. (default: False)'
    )

    args = parser.parse_args()
    maybe_make_directory(args.input_dir)
    maybe_make_directory(args.graph_dir)
    return args
Beispiel #2
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('--dataset', type=str,
                        required=True, choices=['train', 'valid', 'test'],
                        help='Dataset to load the filenames pickle. (required) (default: %(default)s)')
    parser.add_argument('--data_path', type=str,
                        required=True,
                        help='Directory path to the datasets. (required) (default: %(default)s)')
    parser.add_argument('--input_dir', type=str,
                        default='./out',
                        help='Directory path to the pickle files. (default: %(default)s)')
    parser.add_argument('--output_dir', type=str,
                        default='./melspec',
                        help='Directory path to the melspectrograms output. (default: %(default)s)')
    parser.add_argument('--n_mels', type=int,
                        default=128,
                        help='Number of Mel bands to generate. (default: %(default)s)')
    parser.add_argument('--fmax', type=int,
                        default=8000,
                        help='Highest frequency (in Hz). (default: %(default)s)')
    parser.add_argument('--hop_length', type=int,
                        default=1024,
                        help='Number of samples between successive frames. (default: %(default)s)')

    args = parser.parse_args()

    maybe_make_directory(args.input_dir)
    maybe_make_directory(os.path.join(args.output_dir, args.dataset))

    return args
Beispiel #3
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--data_path',
        type=str,
        default='../data/australian_user_reviews.json',
        help='Directory path to the data. (default: %(default)s)')
    parser.add_argument(
        '--input_dir',
        type=str,
        default='reviews',
        help='Directory path to the reviews. (default: %(default)s)')
    parser.add_argument(
        '--output_dir',
        type=str,
        default='bin',
        help='Directory path to the pickle output. (default: %(default)s)')
    parser.add_argument(
        '--verbose',
        action='store_true',
        help='Boolean flag activating console prints. (default: False)')

    args = parser.parse_args()

    maybe_make_directory(args.output_dir)

    return args
    def minimize_with_adam(self, optimizer):
        if self.verbose:
            print('\nMINIMIZING LOSS USING: ADAM OPTIMIZER')
        train_op = optimizer.minimize(self.total_loss)
        init_op = tf.global_variables_initializer()
        self.sess.run(init_op)
        self.sess.run(self.net['input'].assign(self.init_img))

        if self.write_iterations_adam:
            out_dir = os.path.join(self.img_output_dir, self.img_name,
                                   timestr.get_time())
            maybe_make_directory(out_dir)

        for iterations in range(self.max_iterations):
            self.sess.run(train_op)

            # write image at every iteration
            if self.write_iterations_adam:
                img_path = os.path.join(
                    out_dir, self.img_name + str(iterations) + '.png')
                output_img = self.sess.run(self.net['input'])
                write_image(img_path, output_img)
            if iterations % self.print_iterations == 0 and self.verbose:
                curr_loss = self.total_loss.eval()
                print("At iterate {}\tf= {}".format(iterations, curr_loss[0]))
Beispiel #5
0
def save_feature_histogram(sess, model, image_path, layer):
     image = cv2.resize(read_image(image_path), (model.input_shape[1], model.input_shape[0]))
     image = preprocess(image)
     feature_map = model.get_content_features(sess, image, [layer])[layer]
     feature_map = np.ndarray.flatten(feature_map)
     ax = sns.distplot(feature_map, kde=False, norm_hist=False)
     ax.set_title('Layer: {}, mean: {}'.format(layer, feature_map.mean()))
     ax.set_xlabel('activation_value')
     ax.set_ylabel('number of activations')
     maybe_make_directory('plots')
     ax.get_figure().savefig('plots/{}.png'.format(layer))
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input_dir',
        type=str,
        default='reviews',
        help='Directory path to the reviews. (default: %(default)s)')
    parser.add_argument(
        '--output_dir',
        type=str,
        default='figures',
        help='Directory path to the figures. (default: %(default)s)')
    args = parser.parse_args()

    maybe_make_directory(args.output_dir)

    return args
Beispiel #7
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--data_path',
        type=str,
        default='../data/australian_user_reviews.json',
        help='Directory path to the data. (default: %(default)s)')
    parser.add_argument(
        '--output_dir',
        type=str,
        default='reviews',
        help='Directory path to the reviews. (default: %(default)s)')

    args = parser.parse_args()

    maybe_make_directory(args.output_dir)

    return args
Beispiel #8
0
def parse_args():
    parser = argparse.ArgumentParser()

    parser.add_argument(
        '--heuristic',
        type=str,
        required=True,
        choices=['hc', 'hcr', 'sa'],
        help=
        'hc for Hill Climbing, hcr for Hill Climbing reduced, sa for simulated_annealing'
    )
    parser.add_argument(
        '--filename',
        type=str,
        default='100sudoku.txt',
        help=
        'The filename containing sequence of 81 digits. (default: %(default)s)'
    )
    parser.add_argument(
        '--verbose',
        action='store_true',
        help=
        'Boolean flag indicating if statements should be printed to the console.'
    )
    parser.add_argument(
        '--img_output_dir',
        type=str,
        default='./graphs_output',
        help='Relative or absolute directory path to output image graphs.')
    parser.add_argument(
        '--results_dir',
        type=str,
        default='./results',
        help='Relative or absolute directory path to data results.')

    args = parser.parse_args()

    maybe_make_directory(args.img_output_dir)
    maybe_make_directory(args.results_dir)
    return args
Beispiel #9
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('--dataset', type=str,
                        required=True, choices=['train', 'valid', 'test'],
                        help='Dataset to load melspectrograms and save as a npy. (required) (default: %(default)s)')
    parser.add_argument('--resize', action='store_true',
                        help='Boolean flag activating resize of melspectrograms (default: False)')
    parser.add_argument('--size', type=_size, nargs=1,
                        default='32,32',
                        help='Size must be height,width (default: (%(default)s))')
    parser.add_argument('--input_dir', type=str,
                        default='./melspec',
                        help='Directory path to the melspectrograms. (default: %(default)s)')
    parser.add_argument('--output_dir', type=str,
                        default='./out',
                        help='Directory path to the outputs. (default: %(default)s)')
    parser.add_argument('--verbose', action='store_true',
                        help='Boolean flag activating console prints (default: False)')
    args = parser.parse_args()

    maybe_make_directory(args.output_dir)

    return args
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input_path',
        type=str,
        required=True,
        help='Input path to a review. (required) (default: %(default)s)')
    parser.add_argument(
        '--output_dir',
        type=str,
        default='triples',
        help='Directory path to the triples output. (default: %(default)s)')
    parser.add_argument(
        '--interval',
        type=int,
        nargs=2,
        required=True,
        help='Interval of lines to read. (default: %(default)s)')

    args = parser.parse_args()

    maybe_make_directory(args.output_dir)

    return args
Beispiel #11
0
def parse_args():
    parser = argparse.ArgumentParser()

    parser.add_argument('--meta_name',
                        type=str,
                        default='meta_data.txt',
                        help='Configuration file output')

    parser.add_argument(
        '--content_img',
        type=str,
        required=True,
        help='Filename of the content image (example: lion.jpg)')

    parser.add_argument(
        '--content_img_dir',
        type=str,
        default='./image_input',
        help='Directory path to the content image. (default: %(default)s)')

    parser.add_argument(
        '--style_imgs',
        nargs='+',
        type=str,
        required=True,
        help='Filenames of the style images (example: starry-night.jpg)')

    parser.add_argument(
        '--style_imgs_weights',
        nargs='+',
        type=float,
        default=[1.0],
        help=
        'Interpolation weights of each of the style images. (example: 0.5 0.5)'
    )

    parser.add_argument(
        '--style_imgs_dir',
        type=str,
        default='./styles',
        help='Directory path to the style images. (default: %(default)s)')

    parser.add_argument(
        '--init_img_type',
        type=str,
        default='content',
        help='Image used to initialize the network. (default: %(default)s)')

    parser.add_argument(
        '--max_size',
        type=int,
        default=1920,
        help=
        'Maximum width or height of the input images. (default: %(default)s)')

    parser.add_argument(
        '--content_weight',
        type=float,
        default=5e0,
        help='Weight for the content loss function. (default: %(default)s)')

    parser.add_argument(
        '--style_weight',
        type=float,
        default=1e4,
        help='Weight for the style loss function. (default: %(default)s)')

    parser.add_argument(
        '--tv_weight',
        type=float,
        default=1e-3,
        help=
        'Weight for the total variational loss function. Set small (e.g. 1e-3). (default: %(default)s)'
    )

    parser.add_argument(
        '--content_layers',
        nargs='+',
        type=str,
        default=['conv4_2'],
        help='VGG19 layers used for the content image. (default: %(default)s)')

    parser.add_argument(
        '--style_layers',
        nargs='+',
        type=str,
        default=['relu1_1', 'relu2_1', 'relu3_1', 'relu4_1', 'relu5_1'],
        help='VGG19 layers used for the style image. (default: %(default)s)')

    parser.add_argument(
        '--content_layer_weights',
        nargs='+',
        type=float,
        default=[1.0],
        help=
        'Contributions (weights) of each content layer to loss. (default: %(default)s)'
    )

    parser.add_argument(
        '--style_layer_weights',
        nargs='+',
        type=float,
        default=[0.2, 0.2, 0.2, 0.2, 0.2],
        help=
        'Contributions (weights) of each style layer to loss. (default: %(default)s)'
    )

    parser.add_argument('--model_weights',
                        type=str,
                        default='imagenet-vgg-verydeep-19.mat',
                        help='Weights and biases of the VGG-19 network.')

    parser.add_argument(
        '--pooling_type',
        type=str,
        default='avg',
        choices=['avg', 'max'],
        help=
        'Type of pooling in convolutional neural network. (default: %(default)s)'
    )

    parser.add_argument(
        '--device',
        type=str,
        default='/gpu:0',
        choices=['/gpu:0', '/cpu:0'],
        help=
        'GPU or CPU mode.  GPU mode requires NVIDIA CUDA. (default|recommended: %(default)s)'
    )

    parser.add_argument(
        '--img_output_dir',
        type=str,
        default='./image_output',
        help='Relative or absolute directory path to output image and data.')

    parser.add_argument('--img_name',
                        type=str,
                        default='result',
                        help='Filename of the output image.')

    parser.add_argument(
        '--verbose',
        action='store_true',
        help=
        'Boolean flag indicating if statements should be printed to the console.'
    )

    parser.add_argument(
        '--write_iterations_adam',
        action='store_true',
        help=
        'Boolean flag indicating if output images should be written in every iteration under the Adam optimizer.'
    )

    parser.add_argument(
        '--optimizer',
        type=str,
        default='lbfgs',
        choices=['lbfgs', 'adam'],
        help=
        'Loss minimization optimizer.  L-BFGS gives better results.  Adam uses less memory. (default|recommended: %(default)s)'
    )

    parser.add_argument(
        '--learning_rate',
        type=float,
        default=1e0,
        help=
        'Learning rate parameter for the Adam optimizer. (default: %(default)s)'
    )

    parser.add_argument(
        '--max_iterations',
        type=int,
        default=300,
        help=
        'Max number of iterations for the Adam or L-BFGS optimizer. (default: %(default)s)'
    )

    parser.add_argument(
        '--print_iterations',
        type=int,
        default=5,
        help=
        'Number of iterations between optimizer print statements. (default: %(default)s)'
    )

    args = parser.parse_args()

    if args.write_iterations_adam and args.optimizer != 'adam':
        parser.error('The optimizer argument should be adam')

    # normalize weights
    args.style_layer_weights = normalize(args.style_layer_weights)
    args.content_layer_weights = normalize(args.content_layer_weights)
    args.style_imgs_weights = normalize(args.style_imgs_weights)

    maybe_make_directory(args.img_output_dir)
    check_model(args.model_weights)
    return args
Beispiel #12
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--dataset',
        type=str,
        required=True,
        choices=['train', 'valid', 'test'],
        help=
        'Dataset to generate pickle of features. (required) (default: %(default)s)'
    )
    parser.add_argument(
        '--data_path',
        type=str,
        required=True,
        help='Directory path to the datasets. (required) (default: %(default)s)'
    )
    parser.add_argument(
        '--output_dir',
        type=str,
        default='./out',
        help='Directory path to the outputs. (default: %(default)s)')
    parser.add_argument(
        '--temp_avg',
        action='store_true',
        help=
        'Boolean flag activating temporal averaging of features. (default: False)'
    )
    parser.add_argument(
        '--sample',
        action='store_true',
        help=
        'Boolean flag activating sampling of training set. (default: False)')
    parser.add_argument(
        '--n_samples',
        type=int,
        default=5000,
        help=
        'Number of samples to take from each instrument family. (default: %(default)s)'
    )
    parser.add_argument(
        '--n_mfcc',
        type=int,
        default=13,
        help='Number of MFCCs to return. (default: %(default)s)')
    parser.add_argument(
        '--n_mels',
        type=int,
        default=128,
        help='Number of Mel bands to generate. (default: %(default)s)')
    parser.add_argument(
        '--fmax',
        type=int,
        default=8000,
        help='Highest frequency (in Hz). (default: %(default)s)')
    parser.add_argument(
        '--hop_length',
        type=int,
        default=1024,
        help=
        'Number of samples between successive frames. (default: %(default)s)')

    args = parser.parse_args()

    maybe_make_directory(args.output_dir)

    return args