Ejemplo n.º 1
0
def make_features(conf_dict,weight=0.0):
    in_path=conf_dict['img_path']
    out_path=conf_dict['feat_path']
    extractor=select_extractor(conf_dict)
    data=imgs.make_imgs(in_path,norm=True)
    assert(type(data[0])== utils.imgs.Image )
    basic.external.external_features(out_path,data,extractor, weight)
Ejemplo n.º 2
0
def check_transform(img_path, out_path):
    imgset = imgs.make_imgs(img_path, norm=False, transform=imgs.to_3D)
    dirs.make_dir(out_path)
    for i, img_i in enumerate(imgset):
        raw_i = img_i[0]  # imgs.unify_img(img_i)
        print(raw_i.shape)
        name_i = "img" + str(i) + ".jpg"
        new_img_i = imgs.Image(name_i, raw_i)
        new_img_i.save(out_path)
Ejemplo n.º 3
0
def reconstruction(ae_path, img_path, out_path):
    reader = deep.reader.NNReader()
    nn = reader.read(ae_path)  # autoconv.read_conv_ae(ae_path)
    imgset = imgs.make_imgs(img_path, norm=True)
    recon = [nn.reconstructed(img_i) for img_i in imgset]
    recon = imgs.unorm(recon)
    dirs.make_dir(out_path)
    for i, img_i in enumerate(recon):
        img_i.save(out_path, i)
Ejemplo n.º 4
0
def transform_seq(in_path,out_path,extractor):
    imgs_seq= imgs.make_imgs(in_path,norm=True) #imgs.read_images(in_path)
    print(str(extractor))
    seq=[extractor(img_i)
                for img_i in imgs_seq]
    seq=[ seq_i.flatten()  
           for seq_i in seq
             if seq_i!=None]
    txt=files.seq_to_string(seq)
    print(str(in_path))
    print(str(out_path))
    files.save_string(str(out_path)+'.txt',txt)
Ejemplo n.º 5
0
 def parse_action(self,action_dir):
     name,cat,person=self.dataset_format(action_dir)
     img_seq=imgs.make_imgs(action_dir,norm=False)
     return Action(name,img_seq,cat,person)
Ejemplo n.º 6
0
    loss = lasagne.objectives.squared_error(reconstruction, in_var).mean()
    #    l1_penalty = regularize_layer_params(l_hid, l1) * 0.001
    #    loss + l1_penalty  
    updates=lasagne.updates.nesterov_momentum(loss, params, learning_rate=0.1, momentum=0.8) 
    return Autoencoder(hyper_params,l_out,in_var,
                         reduction,reconstruction,loss,updates)    

def build_autoencoder(hyper_params=None):
    num_hidden=hyper_params["num_hidden"]
    input_shape = hyper_params["num_input"]
    l_in =  lasagne.layers.InputLayer(shape=input_shape)
    l_hid = lasagne.layers.DenseLayer(l_in, num_units=num_hidden)
    l_out = lasagne.layers.DenseLayer(l_hid, num_units=input_shape[1])
    in_var=l_in.input_var
    return l_hid,l_out,in_var
   
def read_ae(path):
    with open(path, 'r') as f:
        model = pickle.load(f)
    conv_net=compile_autoencoder(model.hyperparams)
    conv_net.set_model(model)
    return conv_net

if __name__ == "__main__": 
    path_dir="../dataset0a/cats"
    ae_path="../dataset0a/ae"
    imgset=np.array(imgs.make_imgs(path_dir,norm=True))
    model=compile_autoencoder(default_parametrs())
    model=train.test_unsuper_model(imgset,model,num_iter=250)
    model.get_model().save(ae_path)
Ejemplo n.º 7
0
             nonlinearity=lasagne.nonlinearities.rectify)

    flat_layer2=lasagne.layers.DenseLayer(hidden,
             num_units=flat_size,
             nonlinearity=lasagne.nonlinearities.rectify)

    pool_layer2=lasagne.layers.ReshapeLayer(flat_layer2,(pool_size))

    conv_layer2=lasagne.layers.Upscale2DLayer(pool_layer2, pool_size2D)
    
    out_layer= lasagne.layers.TransposedConv2DLayer(
            conv_layer2, num_filters=3, filter_size=filter_size2D,
            nonlinearity=None,#lasagne.nonlinearities.rectify,
            W=lasagne.init.GlorotUniform())
    
    in_var=l_in.input_var
    print(lasagne.layers.get_output_shape( out_layer))
    return hidden,out_layer,in_var#l_hid,l_out,in_var

if __name__ == "__main__": 
    path_dir="../dane2/proj"
    ae_path="../dane2/conv_ae"
    preproc=tools.ImgPreproc()
    imgset=imgs.make_imgs(path_dir,norm=True,transform=preproc)
    print(imgset.shape)
    nn_reader=deep.reader.NNReader()
    model= nn_reader.read(ae_path,nn_reader)
    
    #model=compile_conv_ae(default_parametrs(),preproc)
    model=deep.train.test_unsuper_model(imgset,model,num_iter=100)
    model.get_model().save(ae_path)
Ejemplo n.º 8
0
            loss, params, learning_rate=0.001, momentum=0.9)
    return updates

def default_params():
    return {"input_shape":(None,2,60,60),"num_filters":16,"n_hidden":100,
              "filter_size":(5,5),"pool_size":(4,4),"p":0.5}

def get_model(preproc,nn_path=None,compile=True):
    if(nn_path==None):
        compile=True
    if(compile):
        params=default_params()
        params['n_cats']= data.get_n_cats(y)
        return compile_convnet(params,preproc,False)
    else:
        nn_reader=deep.reader.NNReader(preproc)
        return nn_reader(nn_path,0.1)

if __name__ == "__main__":
    img_path='../dataset2/exp1/train'
    nn_path='../dataset2/exp1/nn_full_nol2'
    preproc=tools.ImgPreproc2D()
    imgset=imgs.make_imgs(img_path,norm=True)
    print("read")
    print(len(imgset))
    x,y=imgs.to_dataset(imgset,data.ExtractCat(),preproc)
    print(x.shape)
    print(y.shape)
    model=get_model(preproc,nn_path,compile=False)
    train.test_super_model(x,y,model,num_iter=100)
    model.get_model().save(nn_path)