deepy/core/graph.py
def create_vars_from_data(self, dataset, split="train"):
        """
        Create vars given a dataset and set test values.
        Useful when dataset is already defined.
        """
        from deepy.core.neural_var import NeuralVariable
        vars = []
        if split == "valid":
            data_split = dataset.valid_set()
        elif split == "test":
            data_split = dataset.test_set()
        else:
            data_split = dataset.train_set()
        first_data_piece = list(data_split)[0]
        for i, numpy_tensor in enumerate(first_data_piece):
            if numpy_tensor.dtype == "int64":
                numpy_tensor = numpy_tensor.astype("int32")
            if numpy_tensor.dtype == "float64":
                numpy_tensor = numpy_tensor.astype(env.FLOATX)
            type_map = {
                0: "scalar",
                1: "vector",
                2: "matrix",
                3: "tensor3",
                4: "tensor4",
                5: "tensor5",
            }
            tensor_type = type_map[numpy_tensor.ndim] if numpy_tensor.ndim in type_map else type_map[0]
            if numpy_tensor.dtype.kind == "i":
                tensor_type = "i" + tensor_type
            theano_tensor = getattr(TT, tensor_type)("input_{}_{}".format(i + 1, tensor_type))
            last_dim = numpy_tensor.shape[-1]
            var = NeuralVariable(theano_tensor, dim=last_dim)
            var.set_test_value(numpy_tensor)
            vars.append(var)
        return vars
def create_vars_from_data(self, dataset, split="train"):
        from deepy.core.neural_var import NeuralVariable
        vars = []
        if split == "valid":
            data_split = dataset.valid_set()
        elif split == "test":
            data_split = dataset.test_set()
        else:
            data_split = dataset.train_set()
        first_data_piece = list(data_split)[0]
        for i, numpy_tensor in enumerate(first_data_piece):
            if numpy_tensor.dtype == "int64":
                numpy_tensor = numpy_tensor.astype("int32")
            if numpy_tensor.dtype == "float64":
                numpy_tensor = numpy_tensor.astype(env.FLOATX)
            type_map = {
                0: "scalar",
                1: "vector",
                2: "matrix",
                3: "tensor3",
                4: "tensor4",
                5: "tensor5",
            }
            tensor_type = type_map[numpy_tensor.ndim] if numpy_tensor.ndim in type_map else type_map[0]
            if numpy_tensor.dtype.kind == "i":
                tensor_type = "i" + tensor_type
            theano_tensor = getattr(TT, tensor_type)("input_{}_{}".format(i + 1, tensor_type))
            last_dim = numpy_tensor.shape[-1]
            var = NeuralVariable(theano_tensor, dim=last_dim)
            var.set_test_value(numpy_tensor)
            vars.append(var)
        return vars
def create_vars_from_data ( self , dataset , split = "train" ) : from deepy . core . neural_var import NeuralVariable vars = [ ] if split == "valid" : data_split = dataset . valid_set ( ) elif split == "test" : data_split = dataset . test_set ( ) else : data_split = dataset . train_set ( ) first_data_piece = list ( data_split ) [ 0 ] for i , numpy_tensor in enumerate ( first_data_piece ) : if numpy_tensor . dtype == "int64" : numpy_tensor = numpy_tensor . astype ( "int32" ) if numpy_tensor . dtype == "float64" : numpy_tensor = numpy_tensor . astype ( env . FLOATX ) type_map = { 0 : "scalar" , 1 : "vector" , 2 : "matrix" , 3 : "tensor3" , 4 : "tensor4" , 5 : "tensor5" , } tensor_type = type_map [ numpy_tensor . ndim ] if numpy_tensor . ndim in type_map else type_map [ 0 ] if numpy_tensor . dtype . kind == "i" : tensor_type = "i" + tensor_type theano_tensor = getattr ( TT , tensor_type ) ( "input_{}_{}" . format ( i + 1 , tensor_type ) ) last_dim = numpy_tensor . shape [ - 1 ] var = NeuralVariable ( theano_tensor , dim = last_dim ) var . set_test_value ( numpy_tensor ) vars . append ( var ) return vars
Create vars given a dataset and set test values.
        Useful when dataset is already defined.
Create vars given a dataset and set test values . Useful when dataset is already defined .