Exemplo n.º 1
0
def load_directions(dir_file):
    """ Load direction(s) from the direction file."""

    f = h5py.File(dir_file, 'r')
    if 'ydirection' in f.keys():
        if 'zdirection' in f.keys():
            if 'tdirection' in f.keys():
                xdirection = h5_util.read_list(f, 'xdirection')
                ydirection = h5_util.read_list(f, 'ydirection')
                zdirection = h5_util.read_list(f, 'zdirection')
                tdirection = h5_util.read_list(f, 'tdirection')
                directions = [xdirection, ydirection, zdirection, tdirection]
            else:
                # 3D plot
                xdirection = h5_util.read_list(f, 'xdirection')
                ydirection = h5_util.read_list(f, 'ydirection')
                zdirection = h5_util.read_list(f, 'zdirection')
                directions = [xdirection, ydirection, zdirection]
        else:
            # 2D plot
            xdirection = h5_util.read_list(f, 'xdirection')
            ydirection = h5_util.read_list(f, 'ydirection')
            directions = [xdirection, ydirection]
    else:
        directions = [h5_util.read_list(f, 'xdirection')]

    return directions
Exemplo n.º 2
0
def load_directions(dir_file):
    """ Load direction(s) from the direction file."""

    f = h5py.File(dir_file, 'r')
    if 'ydirection' in f.keys():  # If this is a 2D plot
        xdirection = h5_util.read_list(f, 'xdirection')
        ydirection = h5_util.read_list(f, 'ydirection')
        directions = [xdirection, ydirection]
    else:
        directions = [h5_util.read_list(f, 'xdirection')]

    return directions
Exemplo n.º 3
0
def load_directions(dir_path):
    f = h5py.File(dir_path, 'r')

    xdirections_data = h5_util.read_list(f, 'xdirection')
    if 'ydirection' in f.keys():
        ydirections_data = h5_util.read_list(f, 'ydirection')
        xdirections = [
            tf.convert_to_tensor(xdata) for xdata in xdirections_data
        ]
        ydirections = [
            tf.convert_to_tensor(ydata) for ydata in ydirections_data
        ]
        directions = [xdirections, ydirections]
    else:
        directions = [[
            tf.convert_to_tensor(xdata) for xdata in xdirections_data
        ]]

    f.close()
    return directions
Exemplo n.º 4
0
        args.ymin, args.ymax, args.ynum = (None, None, None)
        if args.y:
            args.ymin, args.ymax, args.ynum = [
                float(a) for a in args.y.split(':')
            ]
            assert args.ymin and args.ymax and args.ynum, \
                'You specified some arguments for the y axis, but not all'
    except:
        raise Exception(
            'Improper format for x- or y-coordinates. Try something like -1:1:51'
        )

    if args.dir_file:
        # if exist the PCA directions
        f = h5py.File(args.dir_file, 'r')
        xdirection = h5_util.read_list(f, 'xdirection')
        ydirection = h5_util.read_list(f, 'ydirection')

    else:
        # build the random directions
        folder_name = 'fairseq_master' + '/' + args.save_dir + '/Random_'
        xdirection = create_random_direction(states, args.ignore_embedding,
                                             args.ignore)
        ydirection = create_random_direction(states, args.ignore_embedding,
                                             args.ignore)

        folder_name += 'lr=' + str(args.lr[0])
        folder_name += '_optimier=' + str(args.optimizer)
        folder_name += '_ignore_embedding=' + str(args.ignore_embedding)
        if args.ignore:
            folder_name += '_ignoreBN'