GithubHelp home page GithubHelp logo

hypjudy / caffe-dnnh Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 7.0 9.39 MB

A caffe version implementation of a hash network(DNNH/NINH) for similarity-based visual research based on paper: Simultaneous feature learning and hash coding with deep neural networks

Home Page: https://hypjudy.github.io/2017/04/14/caffe-dnnh/

License: MIT License

CMake 2.79% Makefile 0.66% Shell 0.54% C++ 80.37% Cuda 5.60% MATLAB 0.89% Python 9.07% Dockerfile 0.08%

caffe-dnnh's People

Contributors

hypjudy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

caffe-dnnh's Issues

Which one is the anchor of the triplet input when organizing the dataset?

Thanks for reading this issue.
I am trying to organize ImageNet into tripet formation using the provided scripts, but I am a little confused about how to write the relevant LISTFILE. Among "Pic1.jpg Pic2.jpg Pic3.jpg", which one is the anchor image and which one is the positive sample?

Thank you!

use keras

Hi, I use keras to realize this paper. but I do not know whether it has problem or not.
`#!/usr/bin/env python3

-- coding: utf-8 --

"""
Created on Thu Jul 5 10:26:49 2018

@author: dolphin
"""

from future import absolute_import
from future import print_function
import keras
from keras import backend as K
import tensorflow as tf

#define slice function
def slice_f(x,c1,c2):
return x[c1:c2,:]

#define a slice layer using Lamda layer
def slice_hash_layer(inputX,arguemnts):
slice_s=keras.layers.Lambda(slice_f,arguments=arguemnts)(inputX)
hash_s=keras.layers.Dense(1,activation='sigmoid',kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.1))(slice_s)
return hash_s

def deep_hash_model_():
inputX=keras.Input(shape=(224,224,3))
#conv1
conv1_1=keras.layers.Conv2D(96,kernel_size=(11,11),strides=(4,4),activation='relu',
kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.01))(inputX)
conv1_2=keras.layers.Conv2D(96,kernel_size=(1,1),striders=(1,1),activation='relu',
kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.05))(conv1_1)
pool1=keras.layers.MaxPool2D(pool_size=(3,3),strides = (2,2),padding='valid')(conv1_2)
pool1=keras.layers.Dropout(0.5)(pool1)

#conv2
conv2_1=keras.layers.Conv2D(256,kernel_size=(5,5),strides=(1,1),activation='relu',
                      kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.01),
                      padding='same')(pool1)
conv2_2=keras.layers.Conv2D(256,kernel_size=(1,1),strides=(1,1),activation='relu',
                      kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.05),
                      padding='same')(conv2_1)
pool2=keras.layers.MaxPool2D(pool_size=(3,3),strides = (2,2),padding='valid')(conv2_2)

#conv3
conv3_1=keras.layers.Conv2D(384,kernel_size=(3,3),strides=(1,1),activation='relu',
                      kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.01),
                      padding='valid')(pool2)
conv3_2=keras.layers.Conv2D(384,kernel_size=(1,1),strides=(1,1),activation='relu',
                            kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.05),
                            padding='valid')(conv3_1)
pool3=keras.layers.MaxPool2D(pool_size=(3,3),strides = (2,2),padding='valid')(conv3_2)

#conv4
conv4_1=keras.layers.Conv2D(1024,kernel_size=(3,3),strides=(1,1),activation='relu',
                      kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.01),
                      padding='valid')(pool3)
conv4_2=keras.layers.Conv2D(1200,kernel_size=(1,1),strides=(1,1),activation='relu',
                            kernel_initializer=keras.initializers.TruncatedNormal(stddev=0.05),
                            padding='valid')(conv4_1)
pool4=keras.layers.AvgPool2D(kernel_size=(6,6),strides=(1,1),padding='valid')(conv4_2)

#divide and encode module
#use 24 hash-code-bit
slice_hash=[]
for i in range(24):
    arguments={'c1': i*50, 'c2': (i+1)*50}
    slice_hash.append(slice_hash_layer(pool4,arguments))
merge_one=keras.layers.concatenate(slice_hash)  
final_model = keras.models.Model(inputs=inputX, outputs=merge_one)
return final_model

deep_hash_model = deep_hash_model_()

#triplt loss function
#read a line from text,each line include a triple,including three images:
#query_image,positive_image,negtivate_image
batch_size=24
def triplt_loss(y_true,y_pred):
loss=tf.convert_to_tensor(0,dtype=tf.float32)
total_loss=tf.convert_to_tensor(0,dtype=tf.float32)
g=tf.constant(1.0,shape=[1],dtype=tf.float32)
zero=tf.constant(0.0,shape=[1],dtype=tf.float32)
for i in range(0,batch_size,3):
q_embedding=y_pred[i]
p_embedding=y_pred[i+1]
n_embedding=y_pred[i+2]
D_q_p=K.sqrt(K.sum((q_embedding-p_embedding)**2))
D_q_n=K.sqrt(K.sum((q_embedding-n_embedding)**2))
loss=tf.maximum(g+D_q_p-D_q_n,zero)
total_loss=total_loss+loss
total_loss=total_loss/(batch_size/3)
return total_loss `

Can't find query_hashcode.txt

I run "run_test12.sh". I find a file "pool_hashcode.txt" but miss "query_hashcode.txt".

image

It causes a problem when run evaluate_map.cpp.
Please help

test problem

Hello
Thanks for your hard work.
After downloading your source code and datasets and deployed it in runtime/cifar_hash_dataset, I ran./run_train.sh in runtime/12bit and after serveral hours I got

.......
I0913 18:39:05.471935 10028 solver.cpp:311] Iteration 100000, loss = 0.000143271
I0913 18:39:05.471941 10028 solver.cpp:316] Optimization Done.

But when I ran ./run_test.sh after training, I got

......
I0913 19:03:20.272930 12613 caffe.cpp:319] Running for iteration#589...
I0913 19:03:20.296061 12613 caffe.cpp:354] Loss: 0
Reading images's hashcode from files...
Starting querying images in 58999 images' pool...
Finish querying 1 images in 58999 pool images set within the top 10000 returned neighbors!
Mean Average Precision(MAP): 0
MAP of label#1: 0
MAP of label#2: 0
MAP of label#3: 0
MAP of label#4: 0
MAP of label#5: 0
MAP of label#6: 0
MAP of label#7: 0
MAP of label#8: 0
MAP of label#9: 0
MAP of label#10: 0

I have not modified any code and don't know what I did wrong. Could you please give me some advices?
Thank you.

details of partition of NUS-WIDE

hello, I'm asking a details of the partition of the NUS-WIDE data set: how do you randomly select 100 samples in each classes for the query set (and so does the training set)?
I mean, as it's a multi-label data set, a same very sample might be selected several times during the sampling of each classes.
thanks

cifar_hash_dataset.7z downloading

Please, share this dataset on some more available sources like google drive or smth. I just cannot create an baidu account for downloading your dataset. I would much appreciate your help

io.h: No such file or directory

Hello, I am compiling the "convert_triplet_imageset.cpp", and the error is io.h: No such file or directory. Even though there is a "io.h" in "/usr/include/x86_64-linux-gnu/sys", it cannot solve my problem. When I copy the file to "/usr/include", the result just likes the result when I simply comment the "#include <io.h>", in "io.cpp". i.e. "error: ‘_open’ was not declared in this scope","error: ‘_close’ was not declared in this scope" and so on. So what should I do to compile the file "convert_triplet_imageset.cpp"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.