├── DeepNet ├── DBNFit.py ├── DBNFit.pyc ├── DBNPredict.py ├── DBNPredict.pyc ├── DBNdemo.py ├── DBNdemo_dl.py ├── README.md ├── cudamat │ ├── .idea │ │ ├── .name │ │ ├── cudamat.iml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── scopes │ │ │ └── scope_settings.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ ├── INSTALL.txt │ ├── LICENSE.txt │ ├── Makefile │ ├── __init__.py │ ├── __init__.pyc │ ├── cudamat.cu │ ├── cudamat.cuh │ ├── cudamat.py │ ├── cudamat.pyc │ ├── cudamat_kernels.cu │ ├── cudamat_kernels.cuh │ ├── gnumpy.py │ ├── gpu_lock.py │ ├── gpu_lock.pyc │ ├── gpu_lock2.py │ ├── learn.cu │ ├── learn.py │ ├── learn.pyc │ ├── learn_kernels.cu │ ├── learn_kernels.cuh │ ├── libcudalearn.so │ ├── libcudamat.so │ ├── npmat.py │ ├── rnd_multipliers_32bit.txt │ ├── run_on_me_or_pid_quit │ ├── test_cudamat.py │ └── test_learn.py ├── example │ ├── DBNdemo.py │ ├── convert_mnist_to_npy.py │ ├── convert_mnist_to_txt.m │ ├── mnist_classify.mat │ ├── mnist_data.tar.gz │ ├── mnist_data │ │ ├── mnist_classify.mat │ │ ├── mnist_fea.npy │ │ ├── mnist_fea.txt │ │ ├── mnist_lab.npy │ │ └── mnist_lab.txt │ ├── mnist_fea.npy │ ├── mnist_fea.txt │ ├── mnist_lab.npy │ ├── mnist_lab.txt │ ├── multi-modal_demo │ │ ├── SHREC_2007_BOW_1000_viewBased.npy │ │ ├── SHREC_2007_BOW_100_shapeBased.npy │ │ ├── label.npy │ │ └── multiModalityDemo.py │ └── rbmDemo.py ├── model.py ├── model.pyc ├── multiModalityDBNFit.py ├── multiModalityDBNPredict.py ├── multiModalityDemo.py ├── multiModalityDemo_dl.py ├── rbm.py ├── rbm.pyc ├── rbmDemo.py ├── rbmDemo_dl.py ├── rbmFit.py ├── rbmFit.pyc ├── rbmHtoV.py ├── rbmPredict.py ├── rbmPredict.pyc ├── rbmT.py ├── rbmVtoH.py ├── rbmVtoH.pyc ├── set_env.sh ├── util.py └── util.pyc ├── README.md └── multi_modality ├── RBM ├── how_to_run ├── parameters--record.txt ├── run.sh ├── runCR-dl.py ├── runCR.py ├── set_env.sh ├── shapeRetrieval.py ├── tools ├── 12_0.obj ├── 12_1.obj ├── 12_2.obj ├── 12_3.obj ├── 12_4.obj ├── 12_5.obj ├── 12_6.obj ├── 12_7.obj ├── 12_8.obj ├── 12_9.obj ├── extractFeature ├── genViewShapeData.py ├── generateViews.sh ├── lfd.e ├── libcommon.so.1 ├── readShelve.py ├── shapeNpyGen.py ├── test_dir.e ├── tools_meshsimplify.e └── viewNpyGen.py └── viewFeatrueExtract ├── 3DAlignmentCode ├── 12_0.obj ├── 12_1.obj ├── 12_2.obj ├── 12_3.obj ├── 12_4.obj ├── 12_5.obj ├── 12_6.obj ├── 12_7.obj ├── 12_8.obj ├── 12_9.obj ├── 3DAlignmentCode.pro ├── Bitmap.cpp ├── Bitmap.h ├── Circularity.c ├── Circularity.h ├── ColorDescriptor.c ├── ColorDescriptor.h ├── CompactColor.c ├── Convert.c ├── Ds.h ├── Eccentricity.c ├── Eccentricity.h ├── Edge.h ├── FourierDescriptor.c ├── FourierDescriptor.h ├── MORPHOLOGY.H ├── MORPHOLOGY.c ├── Main-orig.c.0 ├── Main.c ├── Makefile ├── RWObj.c ├── RWObj.h ├── RecovAffine.c ├── RecovAffine.h ├── Refine.c ├── Refine.h ├── RegionShape.c ├── RegionShape.h ├── Rotate.c ├── Rotate.h ├── TraceContour.c ├── TraceContour.h ├── TranslateScale.c ├── TranslateScale.h ├── convert.h ├── edge.c ├── fftw │ ├── Makefile │ ├── config.c │ ├── config.h │ ├── executor.c │ ├── f77_func.h │ ├── fcr_1.c │ ├── fcr_10.c │ ├── fcr_11.c │ ├── fcr_12.c │ ├── fcr_128.c │ ├── fcr_13.c │ ├── fcr_14.c │ ├── fcr_15.c │ ├── fcr_16.c │ ├── fcr_2.c │ ├── fcr_3.c │ ├── fcr_32.c │ ├── fcr_4.c │ ├── fcr_5.c │ ├── fcr_6.c │ ├── fcr_64.c │ ├── fcr_7.c │ ├── fcr_8.c │ ├── fcr_9.c │ ├── fftw-int.h │ ├── fftw.h │ ├── fftwf77.c │ ├── fftwnd.c │ ├── fhb_10.c │ ├── fhb_16.c │ ├── fhb_2.c │ ├── fhb_3.c │ ├── fhb_32.c │ ├── fhb_4.c │ ├── fhb_5.c │ ├── fhb_6.c │ ├── fhb_7.c │ ├── fhb_8.c │ ├── fhb_9.c │ ├── fhf_10.c │ ├── fhf_16.c │ ├── fhf_2.c │ ├── fhf_3.c │ ├── fhf_32.c │ ├── fhf_4.c │ ├── fhf_5.c │ ├── fhf_6.c │ ├── fhf_7.c │ ├── fhf_8.c │ ├── fhf_9.c │ ├── fn_1.c │ ├── fn_10.c │ ├── fn_11.c │ ├── fn_12.c │ ├── fn_13.c │ ├── fn_14.c │ ├── fn_15.c │ ├── fn_16.c │ ├── fn_2.c │ ├── fn_3.c │ ├── fn_32.c │ ├── fn_4.c │ ├── fn_5.c │ ├── fn_6.c │ ├── fn_64.c │ ├── fn_7.c │ ├── fn_8.c │ ├── fn_9.c │ ├── fni_1.c │ ├── fni_10.c │ ├── fni_11.c │ ├── fni_12.c │ ├── fni_13.c │ ├── fni_14.c │ ├── fni_15.c │ ├── fni_16.c │ ├── fni_2.c │ ├── fni_3.c │ ├── fni_32.c │ ├── fni_4.c │ ├── fni_5.c │ ├── fni_6.c │ ├── fni_64.c │ ├── fni_7.c │ ├── fni_8.c │ ├── fni_9.c │ ├── frc_1.c │ ├── frc_10.c │ ├── frc_11.c │ ├── frc_12.c │ ├── frc_128.c │ ├── frc_13.c │ ├── frc_14.c │ ├── frc_15.c │ ├── frc_16.c │ ├── frc_2.c │ ├── frc_3.c │ ├── frc_32.c │ ├── frc_4.c │ ├── frc_5.c │ ├── frc_6.c │ ├── frc_64.c │ ├── frc_7.c │ ├── frc_8.c │ ├── frc_9.c │ ├── ftw_10.c │ ├── ftw_16.c │ ├── ftw_2.c │ ├── ftw_3.c │ ├── ftw_32.c │ ├── ftw_4.c │ ├── ftw_5.c │ ├── ftw_6.c │ ├── ftw_64.c │ ├── ftw_7.c │ ├── ftw_8.c │ ├── ftw_9.c │ ├── ftwi_10.c │ ├── ftwi_16.c │ ├── ftwi_2.c │ ├── ftwi_3.c │ ├── ftwi_32.c │ ├── ftwi_4.c │ ├── ftwi_5.c │ ├── ftwi_6.c │ ├── ftwi_64.c │ ├── ftwi_7.c │ ├── ftwi_8.c │ ├── ftwi_9.c │ ├── generic.c │ ├── malloc.c │ ├── planner.c │ ├── putils.c │ ├── rader.c │ ├── rconfig.c │ ├── rexec.c │ ├── rexec2.c │ ├── rfftw.h │ ├── rfftwf77.c │ ├── rfftwnd.c │ ├── rgeneric.c │ ├── rplanner.c │ ├── timer.c │ ├── twiddle.c │ ├── wisdom.c │ └── wisdomio.c ├── file ├── glut-1.h ├── glut32.dll ├── thin.c ├── thin.h └── win_types.h └── extractFeatrue ├── Makefile ├── extractFeature ├── extractFeature.cpp ├── extractFeature.h ├── extractFeature.pro ├── parameter.h └── parameters--record.txt /DeepNet/DBNFit.py: -------------------------------------------------------------------------------- 1 | #/usr/bin/env python 2 | 3 | import numpy as np 4 | import rbm 5 | import rbmFit 6 | 7 | import sys 8 | 9 | def DBNFit(X, label, numHid, isSaveModels = True, name = "/home/cheng/DBN.npy", isSingleDBN = True, **kwargs) : 10 | """implement DBN fitting 11 | X :data(np.array) 12 | label : the label of each sample(np.array, in a row) 13 | numHid : the node of each hidden layer(list)""" 14 | 15 | H = len(numHid) 16 | m = list() 17 | nArg = len(kwargs) 18 | 19 | if H >= 2 : 20 | # train the first rbm model 21 | if nArg >= 1 : 22 | string = "layer" + str(1) 23 | model_ = rbm.rbm(X, numHid[0], **kwargs[string]) 24 | else : 25 | model_ = rbm.rbm(X, numHid[0]) 26 | m.append(model_) 27 | 28 | if isSingleDBN : 29 | for index in range(1, H-1) : 30 | if nArg >= index : 31 | string = "layer" +str(index + 1) 32 | model_ = rbm.rbm(m[index-1].top, numHid[index], **kwargs[string]) 33 | else : 34 | model_ = rbm.rbm(m[index-1].top, numHid[index]) 35 | m.append(model_) 36 | 37 | # train the last rbm model 38 | if nArg >= H : 39 | string = "layer" + str(H) 40 | model_ = rbmFit.rbmFit(m[H-2].top, numHid[H-1], label, **kwargs[string]) 41 | else : 42 | model_ = rbmFit.rbmFit(m[H-2].top, numHid[H-1], label) 43 | m.append(model_) 44 | else : 45 | for index in range(1, H) : 46 | if nArg >= index : 47 | string = "layer" +str(index + 1) 48 | model_ = rbm.rbm(m[index-1].top, numHid[index], **kwargs[string]) 49 | else : 50 | model_ = rbm.rbm(m[index-1].top, numHid[index]) 51 | m.append(model_) 52 | else : 53 | # only a single layer 54 | if isSingleDBN : 55 | if nArg >= 1 : 56 | string = "layer" + str(1) 57 | model_ = rbmFit.rbmFit(X, numHid[0], label, **kwargs[string]) 58 | else : 59 | model_ = rbmFit.rbmFit(X, numHid[0], label) 60 | m.append(model_) 61 | else : 62 | if nArg >= 1 : 63 | string = "layer" + str(1) 64 | model_ = rbm.rbm(X, numHid[0], **kwargs[string]) 65 | else : 66 | model_ = rbm.rbm(X, numHid[0]) 67 | m.append(model_) 68 | 69 | if isSaveModels : 70 | models = np.array(m) 71 | np.save(name, models) 72 | 73 | return m 74 | 75 | if __name__ == "__main__" : 76 | data = np.load(sys.argv[1]) 77 | label = np.load(sys.argv[2]) 78 | nHid = [100, 200] 79 | 80 | # layer1 parameters 81 | p1 = {"maxEpoch" : 100, "modelType" : "BB"} 82 | 83 | # layer2 parameters 84 | p2 = {"maxEpoch" : 100} 85 | 86 | p = {"layer1" : p1, "layer2" : p2} 87 | 88 | models = DBNFit(data, label, nHid, isSingleDBN=True, **p) 89 | print len(models) 90 | print models[0].type," ", models[1].type -------------------------------------------------------------------------------- /DeepNet/DBNFit.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/DBNFit.pyc -------------------------------------------------------------------------------- /DeepNet/DBNPredict.py: -------------------------------------------------------------------------------- 1 | #/usr/bin python 2 | 3 | import rbmPredict 4 | import rbmVtoH 5 | 6 | def DBNPredict(m, X, isSingleDBN = True) : 7 | """implement DBN predict 8 | m : models trained(save in np.array) 9 | X : data to predict""" 10 | 11 | H = len(m) 12 | 13 | if isSingleDBN : 14 | for index in range(H-1) : 15 | X = rbmVtoH.rbmVtoH(m[index], X) 16 | 17 | [prediction, F] = rbmPredict.rbmPredict(m[H-1], X) 18 | 19 | return [prediction, F] 20 | else : 21 | for index in range(H) : 22 | X = rbmVtoH.rbmVtoH(m[index], X) 23 | 24 | return X 25 | 26 | if __name__ == "__main__" : 27 | pass -------------------------------------------------------------------------------- /DeepNet/DBNPredict.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/DBNPredict.pyc -------------------------------------------------------------------------------- /DeepNet/README.md: -------------------------------------------------------------------------------- 1 | DeepNet 2 | ======= 3 | 4 | I implement RBM, DBN, Multi-modal DBN with Python and the majority of matrix operations are executed on GPU. In this project I employ Cudamat and Numpy python libs. 5 | -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/.name: -------------------------------------------------------------------------------- 1 | cudamat -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/cudamat.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /DeepNet/cudamat/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DeepNet/cudamat/INSTALL.txt: -------------------------------------------------------------------------------- 1 | INSTALLATION INSTRUCTIONS: 2 | 3 | 0. Install numpy and nose. 4 | 5 | 1. Install the CUDA SDK. 6 | 7 | 2. Run make in the cudamat directory. 8 | 9 | 3. Make sure everything works by running the test cases: 10 | 11 | python test_cudamat.py 12 | 13 | -------------------------------------------------------------------------------- /DeepNet/cudamat/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009,2010, Volodymyr Mnih 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that 5 | the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the 8 | following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 10 | the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the names of its contributors may be used to endorse or 12 | promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 16 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 19 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 20 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 21 | DAMAGE. 22 | -------------------------------------------------------------------------------- /DeepNet/cudamat/Makefile: -------------------------------------------------------------------------------- 1 | cudamat: 2 | nvcc -O --compiler-bindir=/usr/bin/gcc-4.6 --ptxas-options=-v --compiler-options '-fPIC' -o libcudamat.so --shared cudamat.cu cudamat_kernels.cu -lcublas 3 | nvcc -O --compiler-bindir=/usr/bin/gcc-4.6 --ptxas-options=-v --compiler-options '-fPIC' -o libcudalearn.so --shared learn.cu learn_kernels.cu -lcublas 4 | 5 | clean: 6 | rm *.linkinfo *.pyc *.so 7 | -------------------------------------------------------------------------------- /DeepNet/cudamat/__init__.py: -------------------------------------------------------------------------------- 1 | from cudamat import * 2 | -------------------------------------------------------------------------------- /DeepNet/cudamat/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/cudamat/__init__.pyc -------------------------------------------------------------------------------- /DeepNet/cudamat/cudamat.cuh: -------------------------------------------------------------------------------- 1 | #define ERROR_INCOMPATIBLE_DIMENSIONS -1 2 | #define CUBLAS_ERROR -2 3 | #define CUDA_ERROR -3 4 | #define VIEW_ERROR -4 5 | #define ERROR_TRANSPOSED -5 6 | #define ERROR_GENERIC -6 7 | #define ERROR_TRANSPOSEDNESS -7 8 | #define ERROR_NOT_ON_DEVICE -8 9 | #define ERROR_UNSUPPORTED -9 10 | 11 | struct cudamat { 12 | float* data_host; 13 | float* data_device; 14 | int on_device; 15 | int on_host; 16 | int size[2]; 17 | int is_trans; // 0 or 1 18 | int owns_data; 19 | }; 20 | 21 | struct rnd_struct { 22 | unsigned int* dev_mults; 23 | unsigned long long* dev_words; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /DeepNet/cudamat/cudamat.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/cudamat/cudamat.pyc -------------------------------------------------------------------------------- /DeepNet/cudamat/gpu_lock.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/cudamat/gpu_lock.pyc -------------------------------------------------------------------------------- /DeepNet/cudamat/learn.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "learn_kernels.cuh" 5 | #include "cudamat.cuh" 6 | 7 | extern "C" { 8 | 9 | inline bool checkCUDAError() { 10 | cudaError_t err = cudaGetLastError(); 11 | 12 | if (cudaSuccess != err) 13 | printf("%s\n", cudaGetErrorString( err)); 14 | return cudaSuccess != err; 15 | } 16 | 17 | extern int mult_by_sigmoid_deriv(cudamat* target, cudamat* acts) { 18 | int len = acts->size[0]*acts->size[1]; 19 | 20 | if (acts->is_trans != target->is_trans) 21 | return ERROR_TRANSPOSED; 22 | 23 | if (acts->size[0] != target->size[0] || acts->size[1] != target->size[1]) 24 | return ERROR_INCOMPATIBLE_DIMENSIONS; 25 | 26 | kMultiplyBySigmoidGrad<<>>(acts->data_device, target->data_device, len); 27 | 28 | if (checkCUDAError()) 29 | return CUDA_ERROR; 30 | 31 | return 0; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /DeepNet/cudamat/learn.py: -------------------------------------------------------------------------------- 1 | import pdb 2 | import platform 3 | import warnings 4 | import ctypes as ct 5 | import numpy as np 6 | from cudamat import generate_exception 7 | 8 | if platform.system() == 'Windows': 9 | _cudalearn = ct.cdll.LoadLibrary('libcudalearn.dll') 10 | else: 11 | _cudalearn = ct.cdll.LoadLibrary('libcudalearn.so') 12 | 13 | _cudalearn.mult_by_sigmoid_deriv.restype = ct.c_int 14 | 15 | def mult_by_sigmoid_deriv(target, acts): 16 | """ 17 | target = target * acts * (1 - acts) 18 | 19 | Useful for doing backprop in neural networks with logistic units. 20 | """ 21 | 22 | err_code = _cudalearn.mult_by_sigmoid_deriv(target.p_mat, acts.p_mat) 23 | if err_code: 24 | raise generate_exception(err_code) 25 | -------------------------------------------------------------------------------- /DeepNet/cudamat/learn.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/cudamat/learn.pyc -------------------------------------------------------------------------------- /DeepNet/cudamat/learn_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "learn_kernels.cuh" 2 | 3 | __global__ void kMultiplyBySigmoidGrad(float* act, float* target, const unsigned int len) { 4 | const unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; 5 | const unsigned int numThreads = blockDim.x * gridDim.x; 6 | 7 | for(unsigned int i = idx; i < len; i+= numThreads) { 8 | target[i] = target[i] * act[i] * (1.0f - act[i]); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DeepNet/cudamat/learn_kernels.cuh: -------------------------------------------------------------------------------- 1 | #ifndef EBM_KERNELS_H_ 2 | #define EBM_KERNELS_H_ 3 | 4 | #define NUM_VECTOR_OP_BLOCKS 4096 5 | #define NUM_VECTOR_OP_THREADS_PER_BLOCK 512 6 | 7 | #define NUM_SPARSE_GRAD_BLOCKS 4096 8 | #define NUM_SPARSE_GRAD_THREADS_PER_BLOCK 512 9 | 10 | __global__ void kMultiplyBySigmoidGrad(float* act, float* target, const unsigned int len); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /DeepNet/cudamat/libcudalearn.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/cudamat/libcudalearn.so -------------------------------------------------------------------------------- /DeepNet/cudamat/libcudamat.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/cudamat/libcudamat.so -------------------------------------------------------------------------------- /DeepNet/cudamat/run_on_me_or_pid_quit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | run_on_me_or_pid_quit PID cmd arg1 arg2 5 | 6 | Runs a command after the process PID has completed, or if this process is 7 | interrupted. 8 | 9 | Iain Murray, November 2009, January 2010 10 | """ 11 | 12 | # "Daemonize" this job to stop it getting killed by KeyboardInterrupt when 13 | # pressing Ctrl-c in an interactive python session. 14 | import os 15 | if os.fork() != 0: 16 | os._exit(0) 17 | os.setsid() 18 | if os.fork() != 0: 19 | os._exit(0) 20 | 21 | import sys, os.path, time, signal 22 | 23 | pid = sys.argv[1] 24 | proc_file = '/proc/' + pid 25 | 26 | def final(): 27 | os.execv(sys.argv[2], sys.argv[2:]) 28 | signal.signal(signal.SIGTERM, final) 29 | 30 | try: 31 | while os.path.exists(proc_file): 32 | time.sleep(2) 33 | finally: 34 | final() 35 | -------------------------------------------------------------------------------- /DeepNet/cudamat/test_learn.py: -------------------------------------------------------------------------------- 1 | import pdb 2 | import numpy as np 3 | import nose 4 | import cudamat as cm 5 | import learn as cl 6 | 7 | def setup(): 8 | cm.cublas_init() 9 | 10 | def teardown(): 11 | cm.cublas_shutdown() 12 | 13 | def test_mult_by_sigmoid_deriv(): 14 | m = 256 15 | n = 128 16 | c_targets = np.array(np.random.randn(m, n)*10, dtype=np.float32, order='F') 17 | c_acts = np.array(np.random.rand(m, n), dtype=np.float32, order='F') 18 | 19 | g_targets = cm.CUDAMatrix(c_targets) 20 | g_acts = cm.CUDAMatrix(c_acts) 21 | 22 | c_targets = c_targets * c_acts * (1. - c_acts) 23 | cl.mult_by_sigmoid_deriv(g_targets, g_acts) 24 | 25 | assert np.max(np.abs(c_acts - g_acts.asarray())) < 10**-2, "Error in cudamat.learn.mult_by_sigmoid_deriv exceeded threshold" 26 | 27 | if __name__ == '__main__': 28 | nose.run() 29 | -------------------------------------------------------------------------------- /DeepNet/example/convert_mnist_to_npy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | import os,sys 5 | import numpy as np 6 | 7 | 8 | def convert_txt2npy(fname, opts): 9 | """Convert txt data file to numpy .npy file""" 10 | 11 | # get output file name 12 | fa = os.path.splitext(fname) 13 | 14 | if( len(fa) < 2 ): 15 | print("ERR: input file name not correct! %s\n" % fname) 16 | return 17 | 18 | fn_out = fa[0] + '.npy' 19 | 20 | print('process %s -> %s' % (fname, fn_out)) 21 | 22 | # load txt file 23 | a = np.loadtxt(fname, dtype=opts.dtype) 24 | 25 | # fix label array 26 | if( len(a.shape) == 1 ): 27 | a = a.reshape(a.shape[0], 1) 28 | 29 | # save to .npy 30 | np.save(fn_out, a) 31 | 32 | 33 | def parse_arguments(): 34 | from optparse import OptionParser 35 | 36 | parser = OptionParser(usage="usage: %prog [options] filenames", 37 | version="%prog 1.0") 38 | 39 | parser.add_option("-s", "--sailent", 40 | action="store_true", 41 | dest="sailent", 42 | default=False, 43 | help="Do not show informations") 44 | parser.add_option("-d", "--dtype", 45 | action="store", 46 | dest="dtype", 47 | default="float", 48 | help="npy data type (default float)") 49 | 50 | 51 | (opts, args) = parser.parse_args() 52 | 53 | if( len(args) < 1 ): 54 | parser.error("Wrong number of arguments, please input file name!") 55 | 56 | if( not opts.sailent ): 57 | print("---------------------------------------------------------------") 58 | print("opts = %s" % str(opts)) 59 | print("args = %s" % str(args)) 60 | print("---------------------------------------------------------------") 61 | print("") 62 | 63 | return (opts, args) 64 | 65 | 66 | if( __name__ == '__main__' ): 67 | # parse input arguments 68 | (opts, args) = parse_arguments() 69 | 70 | # process each file 71 | for f in args: 72 | convert_txt2npy(f, opts) 73 | -------------------------------------------------------------------------------- /DeepNet/example/convert_mnist_to_txt.m: -------------------------------------------------------------------------------- 1 | 2 | % load mnist data 3 | d = load('mnist_classify.mat'); 4 | 5 | fea = [d.data; d.testdata]; 6 | lab = [d.labels; d.testlabels]; 7 | 8 | % save to file 9 | save('mnist_fea.txt', '-ascii', 'fea'); 10 | save('mnist_lab.txt', '-ascii', 'lab'); -------------------------------------------------------------------------------- /DeepNet/example/mnist_classify.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_classify.mat -------------------------------------------------------------------------------- /DeepNet/example/mnist_data.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_data.tar.gz -------------------------------------------------------------------------------- /DeepNet/example/mnist_data/mnist_classify.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_data/mnist_classify.mat -------------------------------------------------------------------------------- /DeepNet/example/mnist_data/mnist_fea.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_data/mnist_fea.npy -------------------------------------------------------------------------------- /DeepNet/example/mnist_data/mnist_lab.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_data/mnist_lab.npy -------------------------------------------------------------------------------- /DeepNet/example/mnist_fea.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_fea.npy -------------------------------------------------------------------------------- /DeepNet/example/mnist_lab.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/mnist_lab.npy -------------------------------------------------------------------------------- /DeepNet/example/multi-modal_demo/SHREC_2007_BOW_1000_viewBased.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/multi-modal_demo/SHREC_2007_BOW_1000_viewBased.npy -------------------------------------------------------------------------------- /DeepNet/example/multi-modal_demo/SHREC_2007_BOW_100_shapeBased.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/multi-modal_demo/SHREC_2007_BOW_100_shapeBased.npy -------------------------------------------------------------------------------- /DeepNet/example/multi-modal_demo/label.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/example/multi-modal_demo/label.npy -------------------------------------------------------------------------------- /DeepNet/model.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import shelve 4 | 5 | "rbm model can also be implemented by using dict" 6 | class rbmModel(object) : 7 | """define rbm model""" 8 | 9 | def __init__(self, weight, biasV, biasH, type = None, top = None, weightLabel = None, biasLabel = None, labels = None): 10 | "define the parameter of rbm \ 11 | weight : weight between visible layer and hidden layer \ 12 | biasV : the bias of visible layer \ 13 | biasH : the bias of hidden layer \ 14 | type : rbm type \ 15 | top : the output of hidden layer(label layer does not have this parameter) \ 16 | weightLabel : the weight of label layer(only in last layer of DBN and single layer rbm) \ 17 | biasLabel : the bias of label layer" 18 | 19 | self.weight = weight 20 | self.biasV = biasV 21 | self.biasH = biasH 22 | self.type = type 23 | self.top = top 24 | self.weightLabel = weightLabel 25 | self.biasLabel = biasLabel 26 | self.labels = labels 27 | 28 | def save(self, name = "data/rbm.shelve") : 29 | "save single rbm model using numpy as *.npy format" 30 | m = shelve.open(name) 31 | m["model"] = self 32 | m.close() 33 | 34 | def load(self, name = "data/rbm.shelve") : 35 | 36 | m = shelve.open(name) 37 | self = m["model"] 38 | return self 39 | 40 | if __name__ == "__main__" : 41 | pass 42 | -------------------------------------------------------------------------------- /DeepNet/model.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/model.pyc -------------------------------------------------------------------------------- /DeepNet/multiModalityDBNFit.py: -------------------------------------------------------------------------------- 1 | #/usr/bin/env python 2 | 3 | import numpy as np 4 | 5 | import DBNFit 6 | import rbmFit 7 | 8 | import sys 9 | 10 | def multiModalityDBNFit(X, label, numHid, numJoint, isSaveModel=True, modelName = None, **kwargs) : 11 | """"multi-modality DBN fitting 12 | X : input data for all modalities 13 | lable : the label of each sample 14 | numHid : the node of each hidden layer of each modality and must be a two-dimension array 15 | numJoint : the node of joint layer(if there is only one modality, numJoint can be seen as the node of last hidden layer) 16 | 17 | for example : multiModalityDBN([img, txt], label, [[300,400], [200,300]])""" 18 | 19 | # cal the total number of modality 20 | N = len(X) 21 | if N != len(numHid) : 22 | print "the X and numHid must have the same length" 23 | sys.exit() 24 | 25 | models = list() 26 | 27 | # train all modalities 28 | for index in range(N) : 29 | string = "modality" + str(index+1) 30 | 31 | # here isSingleDBN must be set to False 32 | m = DBNFit.DBNFit(X[index], label, numHid[index], isSaveModels=False, name = "./DBN.npy", \ 33 | isSingleDBN = False, **kwargs[string]) 34 | models.append(m) 35 | 36 | # train the joint layer 37 | # concatenate all modalities data 38 | # nDim = 0 39 | # nCase = label.size 40 | # for index in range(N) : 41 | # nDim = nDim + numHid[index][-1] 42 | 43 | # inputData = np.zeros((nCase, nDim)) 44 | for index in range(N-1) : 45 | if index == 0 : 46 | data = np.append(models[index][-1].top, models[index+1][-1].top, axis = 1) 47 | else : 48 | data = np.append(data, models[index+1][-1].top, axis = 1) 49 | 50 | string = "joint" 51 | m = rbmFit.rbmFit(data, numJoint, label, **kwargs[string]) 52 | 53 | models.append(m) 54 | 55 | if isSaveModel : 56 | models_ = np.array(models) 57 | if modelName == None : 58 | modelName = "../data/model/multi-modalityDBN.npy" 59 | 60 | np.save(modelName, models_) 61 | 62 | return models -------------------------------------------------------------------------------- /DeepNet/multiModalityDBNPredict.py: -------------------------------------------------------------------------------- 1 | #/usr/bin/env python 2 | 3 | import numpy as np 4 | 5 | import DBNPredict 6 | import rbmPredict 7 | 8 | import sys 9 | 10 | def multiModalityDBNPredict(models, X) : 11 | """ 12 | models : trained models including joint layer 13 | X : input data for all modalities""" 14 | N = len(X) 15 | 16 | if N != len(models)-1 : 17 | print "error" 18 | sys.exit() 19 | 20 | for index in range(N) : 21 | X[index] = DBNPredict.DBNPredict(models[index], X[index], isSingleDBN=False) 22 | 23 | # concatenate all modalities data 24 | for index in range(N-1) : 25 | if index == 0 : 26 | data = np.append(X[index], X[index+1], axis = 1) 27 | else : 28 | data = np.append(data, X[index+1], axis = 1) 29 | 30 | [prediction, F] = rbmPredict.rbmPredict(models[-1], data) 31 | 32 | return [prediction, F] 33 | 34 | if __name__ == "__main__" : 35 | pass -------------------------------------------------------------------------------- /DeepNet/rbm.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/rbm.pyc -------------------------------------------------------------------------------- /DeepNet/rbmDemo_dl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | from optparse import OptionParser as OP 5 | 6 | import rbmFit 7 | import rbmPredict 8 | import util 9 | import shelve 10 | 11 | import numpy as np 12 | 13 | def testRBM(opts) : 14 | """show how to use RBM to do classification""" 15 | nHid = 1000 16 | 17 | # split data and label into train dataset and test dataset 18 | trainData = np.load(opts.trainFeature) 19 | trainLabel = np.load(opts.trainLabel) 20 | testData = np.load(opts.testFeature) 21 | testLabel = np.load(opts.testLabel) 22 | 23 | nTrain = trainLabel.size 24 | nTest = testLabel.size 25 | 26 | p = {"maxEpoch" : options.maxEpoch} 27 | 28 | m = rbmFit.rbmFit(trainData, nHid, trainLabel, isSaveModel=True, name=opts.model, **p) 29 | 30 | [trainR, F1] = rbmPredict.rbmPredict(m, trainData) 31 | [testR, F2] = rbmPredict.rbmPredict(m, testData) 32 | 33 | trainK = 0 34 | for x in range(nTrain) : 35 | if trainLabel[x] != trainR[x] : 36 | trainK = trainK + 1 37 | 38 | testK = 0 39 | for x in range(nTest) : 40 | if testLabel[x] != testR[x] : 41 | testK = testK+1 42 | 43 | print "---------------------------------------" 44 | print "train classification rate : %f " % (1-trainK*1.0/nTrain) 45 | print "test classification rate : %f " % (1-testK*1.0/nTest) 46 | print "---------------------------------------" 47 | 48 | if opts.isSaveResult : 49 | result = shelve.open(options.resultName) 50 | result["nHid"] = nHid 51 | result["maxEpoch"] = options.maxEpoch 52 | result["trainAcc"] = 1-trainK*1.0/nTrain 53 | result["testAcc"] = 1-testK*1.0/nTest 54 | result.close() 55 | 56 | def parseOptions(argv) : 57 | """parse arguments""" 58 | parser = OP(usage="%prog [options] args") 59 | 60 | parser.add_option("-e", "--maxEpoch", 61 | action="store", 62 | dest="maxEpoch", 63 | default=1000, 64 | type='int', 65 | help="Iteration number") 66 | 67 | parser.add_option("--trainFeature", 68 | action="store", 69 | dest="trainFeature", 70 | # default='testData/feature.npy', 71 | help="trainning Feature file name") 72 | parser.add_option("--testFeature", 73 | action="store", 74 | dest="testFeature", 75 | # default='testData/feature.npy', 76 | help="testing Feature file name") 77 | 78 | parser.add_option("--trainLabel", 79 | action="store", 80 | dest="trainLabel", 81 | # default='testData/label.npy', 82 | help="train Label file name") 83 | parser.add_option("--testLabel", 84 | action="store", 85 | dest="testLabel", 86 | # default='testData/label.npy', 87 | help="test Label file name") 88 | parser.add_option("--model", 89 | action="store", 90 | dest="model", 91 | # default='testData/DBNModel.npy', 92 | help="DBN model file name") 93 | parser.add_option("--verbose", 94 | action = "store", 95 | dest="isSaveResult", 96 | default="True", 97 | help="whether to save classification result or not") 98 | parser.add_option( "--name", 99 | action="store", 100 | dest="resultName", 101 | # default="testData/classification.shelve", 102 | help="the file name of classification result, only works when -b is true") 103 | 104 | (options, args) = parser.parse_args(argv) 105 | 106 | print "-------------------------------------" 107 | print "options : ", options 108 | print "args : ", args 109 | print "-------------------------------------" 110 | 111 | return (options, args) 112 | 113 | if __name__ == "__main__" : 114 | (options, argv) = parseOptions(sys.argv) 115 | testRBM(options) 116 | -------------------------------------------------------------------------------- /DeepNet/rbmFit.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/rbmFit.pyc -------------------------------------------------------------------------------- /DeepNet/rbmHtoV.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin python 2 | 3 | import cudamat as cm 4 | import numpy as np 5 | 6 | def rbmHtoV(m, X) : 7 | """convey data fron hidden layer to visible layer""" 8 | cm.cublas_init() 9 | 10 | # copy data to GPU 11 | data = cm.CUDAMatrix(cm.reformat(X)) 12 | weight = cm.CUDAMatrix(cm.reformat(m.weight)) 13 | biasV = cm.CUDAMatrix(cm.reformat(m.biasV)) 14 | 15 | nCase = X.shape[0] 16 | nVis = biasV.asarray().size 17 | VisActP = cm.CUDAMatrix(np.zeros((nCase, nVis))) 18 | 19 | if m.type == "BB" : 20 | cm.dot(data, weight.T, target = VisActP) 21 | VisActP.add_row_vec(biasV) 22 | VisActP.apply_sigmoid() 23 | elif m.type == "BG" : 24 | cm.dot(data, weight.T, target = VisActP) 25 | VisActP.add_row_vec(biasV) 26 | elif m.type == "GB" : 27 | pass 28 | 29 | result = VisActP.asarray() 30 | 31 | #free device memory 32 | data.free_device_memory() 33 | 34 | weight.free_device_memory() 35 | biasV.free_device_memory() 36 | VisActP.free_device_memory() 37 | 38 | cm.shutdown() 39 | 40 | return result 41 | -------------------------------------------------------------------------------- /DeepNet/rbmPredict.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import cudamat as cm 3 | import numpy as np 4 | 5 | import sys 6 | 7 | import model 8 | 9 | def rbmPredict(m, X) : 10 | """using trained rbm model to do prediction""" 11 | nClass = m.labels.size 12 | numCase = X.shape[0] 13 | 14 | # This part is executed on CPU 15 | # define the free energy 16 | # FF = np.zeros((numCase, nClass)) 17 | # FFcol = np.zeros((numCase, 1)) 18 | # for index in range(nClass) : 19 | # temp = np.zeros((numCase, nClass)) 20 | # temp[:, index] = 1 21 | # 22 | # tt = np.emath.log(np.exp(np.dot(X, m.weight)+ np.dot(temp, m.weightLabel) + m.biasH)+1) 23 | # 24 | # FFcol = temp[:,index] * m.biasLabel[0,index] + np.sum(tt,axis = 1) 25 | # 26 | # FF[:, index] = FFcol 27 | # 28 | # [x, y] = np.where(np.abs(FF - np.max(FF, axis=1, keepdims=True)) < 1e-5) 29 | 30 | # result = np.zeros(y.shape) 31 | 32 | # for index in range(y.size) : 33 | # result[index] = m.labels[y[index]] 34 | 35 | 36 | # The following part runs on GPU 37 | cm.cublas_init() 38 | 39 | # copy data to GPU 40 | data = cm.CUDAMatrix(cm.reformat(X)) 41 | weight = cm.CUDAMatrix(cm.reformat(m.weight)) 42 | biasH = cm.CUDAMatrix(cm.reformat(m.biasH)) 43 | weightLabel = cm.CUDAMatrix(cm.reformat(m.weightLabel)) 44 | biasLabel = cm.CUDAMatrix(cm.reformat(m.biasLabel)) 45 | 46 | F = cm.CUDAMatrix(np.zeros((numCase, nClass))) 47 | Fcol = cm.CUDAMatrix(np.zeros((numCase, 1))) 48 | temp = cm.CUDAMatrix(np.zeros((numCase, nClass))) 49 | 50 | tt = cm.CUDAMatrix(np.zeros((numCase, biasH.asarray().size))) 51 | for index in range(nClass) : 52 | temp.assign(0) 53 | 54 | temp.set_col_slice(index, index+1, 1) 55 | 56 | tt = cm.dot(data, weight) 57 | tt.add_dot(temp, weightLabel) 58 | tt.add_row_vec(biasH) 59 | cm.log_1_plus_exp(tt, target = tt, exact = True) 60 | 61 | Fcol = cm.sum(tt, axis = 1) 62 | Fcol.add_mult(temp.get_col_slice(index, index+1), biasLabel.numpy_array[0, index]) 63 | 64 | F.set_col_slice(index, index+1, Fcol) 65 | 66 | tt.free_device_memory() 67 | 68 | F.copy_to_host() 69 | [x, y] = np.where(np.abs(F.numpy_array - np.max(F.numpy_array, axis=1, keepdims=True)) < 1e-5) 70 | 71 | # free device memory 72 | data.free_device_memory() 73 | 74 | weight.free_device_memory() 75 | biasH.free_device_memory() 76 | biasLabel.free_device_memory() 77 | weightLabel.free_device_memory() 78 | 79 | F.free_device_memory() 80 | Fcol.free_device_memory() 81 | temp.free_device_memory() 82 | 83 | cm.shutdown() 84 | 85 | result = np.zeros(y.shape) 86 | 87 | for index in range(y.size) : 88 | result[index] = m.labels[y[index]] 89 | 90 | return [result, F.numpy_array] 91 | 92 | if __name__ == "__main__" : 93 | pass 94 | -------------------------------------------------------------------------------- /DeepNet/rbmPredict.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/rbmPredict.pyc -------------------------------------------------------------------------------- /DeepNet/rbmVtoH.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin python 2 | 3 | import cudamat as cm 4 | import numpy as np 5 | 6 | def rbmVtoH(m, X) : 7 | """convey data fron visual layer to hidden layer""" 8 | cm.cublas_init() 9 | 10 | # copy data to GPU 11 | data = cm.CUDAMatrix(cm.reformat(X)) 12 | weight = cm.CUDAMatrix(cm.reformat(m.weight)) 13 | biasH = cm.CUDAMatrix(cm.reformat(m.biasH)) 14 | 15 | nCase = X.shape[0] 16 | nHid = biasH.asarray().size 17 | 18 | hidActP = cm.CUDAMatrix(np.zeros((nCase, nHid))) 19 | 20 | if m.type == "BB" : 21 | cm.dot(data, weight, target = hidActP) 22 | hidActP.add_row_vec(biasH) 23 | hidActP.apply_sigmoid() 24 | elif m.type == "BG" : 25 | cm.dot(data, weight, target = hidActP) 26 | hidActP.add_row_vec(biasH) 27 | elif m.type == "GB" : 28 | pass 29 | 30 | result = hidActP.asarray() 31 | 32 | # free device memory 33 | data.free_device_memory() 34 | 35 | weight.free_device_memory() 36 | biasH.free_device_memory() 37 | hidActP.free_device_memory() 38 | 39 | cm.shutdown() 40 | 41 | return result 42 | -------------------------------------------------------------------------------- /DeepNet/rbmVtoH.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/rbmVtoH.pyc -------------------------------------------------------------------------------- /DeepNet/set_env.sh: -------------------------------------------------------------------------------- 1 | DEEPNET_PATH=/home/cheng/work_shop/github/DeepNet/DeepNet 2 | 3 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DEEPNET_PATH/cudamat/:$DEEPNET_PATH/cudamat_conv 4 | export PYTHONPATH=$DEEPNET_PATH:$DEEPNET_PATH/cudamat/:$DEEPNET_PATH/cudamat_conv 5 | 6 | -------------------------------------------------------------------------------- /DeepNet/util.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import random 4 | import sys 5 | 6 | import numpy as np 7 | import cudamat as cm 8 | 9 | def processOptions(arg, **kwargs) : 10 | """process options for rbm \ 11 | arg : a dict to save the setting you want to apply to the rbm \ 12 | kwargs : a key word parameter to save the default setting of rbm""" 13 | result = [] 14 | 15 | if kwargs is None : 16 | kwargs = {} 17 | kwargs.update(arg) 18 | 19 | return kwargs 20 | 21 | def ceil(m ,n) : 22 | """ m and n must be integer""" 23 | if m%n != 0 : 24 | return m/n+1 25 | else : 26 | return m/n 27 | 28 | def shuffle(data, label) : 29 | """shuffle data and label""" 30 | size = label.shape[0] 31 | seq = random.sample(range(size), size) 32 | 33 | dataTemp = np.zeros(data.shape) 34 | labelTemp = np.zeros(label.shape) 35 | 36 | for index, x in enumerate(seq) : 37 | dataTemp[index, :] = data[x, :] 38 | labelTemp[index, :] = label[x, :] 39 | 40 | return [dataTemp, labelTemp] 41 | 42 | def shuffleMore(data1, data2, label) : 43 | "shuffle data1 and data2, both have the same corresponding label" 44 | size = label.shape[0] 45 | seq = random.sample(range(size), size) 46 | 47 | dataTemp1 = np.zeros(data1.shape) 48 | dataTemp2 = np.zeros(data2.shape) 49 | labelTemp = np.zeros(label.shape) 50 | 51 | for index, x in enumerate(seq) : 52 | dataTemp1[index, :] = data1[x, :] 53 | dataTemp2[index, :] = data2[x, :] 54 | labelTemp[index, :] = label[x, :] 55 | 56 | return [dataTemp1, dataTemp2, labelTemp] 57 | 58 | def matrixLabel(label) : 59 | """conver the label format from array to matrix 60 | label : np.array()""" 61 | size = label.size 62 | 63 | minLabel = np.min(label) 64 | maxLabel = np.max(label) 65 | 66 | result = np.zeros((size, maxLabel-minLabel+1)) 67 | for index, x in enumerate(label) : 68 | result[index, int(x-1)] = 1 69 | 70 | return result 71 | 72 | def softmax(prob) : 73 | """compute the softmax function 74 | prob : size is batchSize * nclass 75 | numpy.array format or cm.CUDAMatrix 76 | softmax function : result(row,col) = exp(prob)/sum_row(exp(prob))""" 77 | # case cuda matrix 78 | isCuda = False 79 | if isinstance(prob, cm.CUDAMatrix) : 80 | isCuda = True 81 | prob.copy_to_host() 82 | 83 | # free device memory 84 | prob.free_device_memory() 85 | 86 | # compute softmax 87 | prob = np.exp(prob.numpy_array) 88 | mu = prob/np.sum(prob, axis = 1, keepdims=True) 89 | 90 | # softmax sample 91 | mu = mu/np.sum(mu, axis = 1, keepdims=True) 92 | 93 | oneofn = np.zeros(mu.shape) 94 | # [x, y] = np.where(np.abs(mu - np.max(mu, axis=1, keepdims=True)) < 1e-5) 95 | # oneofn[x, y] = 1 96 | 97 | sample = np.cumsum(mu, axis = 1) 98 | rows = sample.shape[0] 99 | sample = sample > np.random.rand(rows,1) 100 | 101 | for index in range(rows) : 102 | [ix] = np.where(sample[index, :] == True) 103 | if ix.size == 0 : 104 | i = 0 105 | else : 106 | i = min(ix) 107 | 108 | oneofn[index, i] = 1 109 | 110 | if isCuda : 111 | oneofn = cm.CUDAMatrix(oneofn) 112 | 113 | return oneofn 114 | 115 | 116 | def testSoftmax(data) : 117 | A = cm.CUDAMatrix(data) 118 | sample = softmax(A) 119 | 120 | if __name__ == "__main__" : 121 | data = np.load(sys.argv[1]) 122 | testSoftmax(data) -------------------------------------------------------------------------------- /DeepNet/util.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/DeepNet/util.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DeepNet 2 | ============ 3 | 4 | In this project, I implement a deep learning toolbox (DeepNet) including RBM, DBN, Multi-modal DBN with Python, in which the majority of matrix operations are carried on GPU by using the Cudamat to speed up the calculation process. There are some examples to show how to use this package. 5 | 6 | This project make some references to the matlab code in https://github.com/dmus/API-Project. However, in comparison with the matlab 7 | code, our version improves the performance 25 times (test on the Mnist data). 8 | 9 | Requirements 10 | ============ 11 | * NumPy (http://www.numpy.org/) 12 | * Cudamat (already included, https://github.com/cudamat/cudamat) 13 | 14 | Usage 15 | ============ 16 | To use the toolbox, following steps are needed. 17 | 18 | (1) compile the Cudamat library : 19 | ```python 20 | cd (directory to DeepNet) 21 | cd DeepNet/RBM/cudamat/ 22 | Make (note : correct path to gcc-4.6 or below version compiler should be given in Makefile) 23 | ``` 24 | 25 | (2) change directory to RBM/, then set the DEEPNET_PATH variable in set_env.sh file to the RBM/ path in your computer 26 | 27 | (3) run command : 28 | ``` 29 | source set_env.sh 30 | ``` 31 | 32 | (4) We provide some demo programs in this toolbox. 33 | 34 | **RBM and DBN demos** 35 | --------------- 36 | For RBM and DBN demos, we use Mnist data, which has been contained in our toolbox. To run these demos, you should first uncompress the data in example/. 37 | ```python 38 | cd example/ 39 | tar -xzvf mnist_data.tar.gz 40 | python rbmDemo.py 41 | or 42 | python DBNdemo.py 43 | ``` 44 | For help information, run 45 | ```python 46 | python rbmDemo.py --help 47 | or 48 | python DBNdemo.py --help 49 | ``` 50 | **Multi-modal DBN demo** 51 | --------------- 52 | For multi-modal demo, we employ SHREC 2007 feature data to show the usage. How the data is generated has been elaborated in our paper "Multi-modal Feature Fusion for 3D Shape Recognition and Retrieval". 53 | To run this demo, change directory to multi-modal_demo/ and run 54 | ```python 55 | python multiModalityDemo.py 56 | ``` 57 | For help information, run 58 | ```python 59 | python multiModalityDemo.py --help 60 | ``` 61 | 62 | Platform 63 | =========== 64 | This code is only tested on Linux mint-16 64-bit. 65 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /multi_modality/RBM: -------------------------------------------------------------------------------- 1 | ../DeepNet/ -------------------------------------------------------------------------------- /multi_modality/how_to_run: -------------------------------------------------------------------------------- 1 | # run multi-modality DBN 2 | python runCR.py -a multi-modality -v data/shrec2007/SHREC_2007_BOW_1000_viewBased.npy -s data/shrec2007/SHREC_2007_BOW_100_shapeBased.npy -l data/shrec2007/label.npy -e 2000 3 | or 4 | python runCR.py --action multi-modality --viewBasedFeature data/shrec2007/SHREC_2007_BOW_1000_viewBased.npy --shapeBasedFeature data/shrec2007/SHREC_2007_BOW_100_shapeBased.npy --label data/shrec2007/label.npy --maxEpoch 2000 5 | 6 | # run DBN-view 7 | python runCR.py --action DBN_view --viewBasedFeature data/shrec2007/SHREC_2007_BOW_1000_viewBased.npy --label data/shrec2007/label.npy --maxEpoch 2000 8 | 9 | #run DBN-shape 10 | python runCR.py --action DBN_shape --shapeBasedFeature data/shrec2007/SHREC_2007_BOW_100_shapeBased.npy --label data/shrec2007/label.npy --maxEpoch 2000 11 | 12 | # run RBM-view 13 | python runCR.py --action rbm_view --viewBasedFeature data/shrec2007/SHREC_2007_BOW_1000_viewBased.npy --label data/shrec2007/label.npy --maxEpoch 2000 --nHid 1000 14 | 15 | # run RBM-shape 16 | python runCR.py --action rbm_shape --shapeBasedFeature data/shrec2007/SHREC_2007_BOW_100_shapeBased.npy --label data/shrec2007/label.npy --maxEpoch 2000 --nHid 1000 17 | 18 | # run multi-modality-dl 19 | python runCR-dl.py --action multi-modality --viewBasedFeature data/dl/dl_viewBsed_Bow_3000.npy --shapeBasedFeature data/dl/dl_shapeBased_Bow_3000.npy --label data/dl/Bow_3000_label.npy --maxEpoch 2000 --trainViewBasedFeature data/dl/dl_train_viewBased_BOW.npy --testViewBasedFeature data/dl/dl_test_viewBased_BOW.npy --trainShapeBasedFeature data/dl/dl_train_shapeBased_BOW.npy --testShapeBasedFeature data/dl/dl_test_shapeBased_BOW.npy --trainLabel data/dl/dl_train_BOW_label.npy --testLabel data/dl/dl_test_BOW_label.npy 20 | 21 | -------------------------------------------------------------------------------- /multi_modality/parameters--record.txt: -------------------------------------------------------------------------------- 1 | ---23:13:47, 2014-8-22--- 2 | imageFilePath : /home/cheng/work_shop/code/multi_modality/data/viewFeatureData/xie_data/xie_data_viewListImage.txt 3 | nVocabulary : 1000 4 | pathToSaveBOW : /home/cheng/work_shop/code/multi_modality/data/viewFeatureData/xie_data/xie_data 5 | method : 0 6 | lambda : 0.000100 7 | knn : 5 8 | 9 | ---10:32:55, 2014-8-23--- 10 | imageFilePath : /home/cheng/work_shop/code/multi_modality/data/viewFeatureData/xie_data/xie_data_viewListImage.txt 11 | nVocabulary : 1000 12 | pathToSaveBOW : /home/cheng/work_shop/code/multi_modality/data/viewFeatureData/xie_data/xie_data 13 | method : 0 14 | lambda : 0.000100 15 | knn : 5 16 | 17 | -------------------------------------------------------------------------------- /multi_modality/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # the diectory of 3d path database 4 | shapePath=/home/cheng/work_shop/myProjects/3D_data/xie_data/ 5 | 6 | # where to save the temporary files 7 | dirToSaveViewFeature=/home/cheng/work_shop/code/multi_modality/data/viewFeatureData/xie_data 8 | 9 | # tool to generate file list 10 | makeFileList=tools/test_dir.e 11 | 12 | # convert shape format 13 | convertShape=tools/tools_meshsimplify.e 14 | 15 | # generate views 16 | generateViews=tools/lfd.e 17 | 18 | # generate bow 19 | generateBow=tools/extractFeature 20 | 21 | # generate npy data 22 | 23 | # generate off file list and then conver the off format to obj format 24 | generateObjFile(){ 25 | echo "generate obj files ... " 26 | fileListName=$(ls $shapePath) 27 | objList=$(ls $dirToSaveViewFeature/*obj*) 28 | 29 | # if [ ${#objList[@]} -eq 0 ] 30 | # then 31 | if [ ! -d $dirToSaveViewFeature ] 32 | then 33 | mkdir -p ${dirToSaveViewFeature} 34 | fi 35 | 36 | for file in $fileListName 37 | do 38 | echo $shapePath$file 39 | fileToSave=$dirToSaveViewFeature/$file"_offList.txt" 40 | $makeFileList $shapePath$file | grep ".off$" > $fileToSave 41 | done 42 | 43 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:tools 44 | for file in $(ls $shapePath) 45 | do 46 | temp=$dirToSaveViewFeature/$file 47 | fileToSave=$temp"_objList.txt" 48 | 49 | $convertShape off2obj $temp"_offList.txt" > $temp"_obj" 50 | 51 | echo "generating $fileToSave" 52 | for line in $(more $temp"_obj") 53 | do 54 | echo ${line%".obj"} >> $fileToSave 55 | done 56 | 57 | rm $temp"_offList.txt" $temp"_obj" 58 | done 59 | # fi 60 | } 61 | 62 | # generate label index and label map for shape dataset 63 | generateLabelFile(){ 64 | echo "generate label files ... " 65 | 66 | labelList=$(ls $dirToSaveViewFeature/*_labelMap.txt) 67 | 68 | if [ ${#labelList[@]} -eq 0 ] 69 | then 70 | objList=$(ls $dirToSaveViewFeature) 71 | for file in $objList 72 | do 73 | prefix=${file%_*} 74 | for line in $(more $dirToSaveViewFeature/$file) 75 | do 76 | labelFile=$dirToSaveViewFeature/$prefix"_label.txt" 77 | tempLine=${line%/*} 78 | echo ${tempLine##*/} >> $labelFile 79 | done 80 | done 81 | 82 | labelList=$(ls $dirToSaveViewFeature/*_label.txt) 83 | for file in $labelList 84 | do 85 | prefix=${file%_*} 86 | labelMap=$prefix"_labelMap.txt" 87 | labelIndex=$prefix"_labelIndex.txt" 88 | label=0 89 | lastLine="" 90 | for line in $(more $file) 91 | do 92 | if [ "$line" != "$lastLine" ] 93 | then 94 | label=$(($label+1)) 95 | lastLine=$line 96 | echo $label $line >> $labelMap 97 | fi 98 | 99 | echo $label >> $labelIndex 100 | done 101 | 102 | rm $file 103 | done 104 | fi 105 | } 106 | 107 | generateViews(){ 108 | echo "generate views ... " 109 | 110 | # sudo chmod -R +r $dirToSaveViewFeature 111 | # viewImgFileList=$(ls $dirToSaveViewFeature/*_viewListImage.txt) 112 | # if [ ${#viewImgFileList[@]} -eq 0 ] 113 | # then 114 | 115 | for file in $(ls $dirToSaveViewFeature/*_objList.txt) 116 | do 117 | postfix=${file##*/} 118 | prefix=${file%_*} 119 | $generateViews $file $prefix"_labelIndex.txt" $prefix"_viewListImage.txt" $prefix"_image" tools 120 | echo $file 121 | done 122 | # fi 123 | } 124 | 125 | generateFeature() 126 | { 127 | echo "generate bow ..." 128 | # bowFileList=$(ls $dirToSaveViewFeature/*_BOW.txt) 129 | # if [ ${#bowFileList[@]} -eq 0 ] 130 | # then 131 | for file in $(ls $dirToSaveViewFeature/*_viewListImage.txt) 132 | do 133 | postfix=${file##*/} 134 | case "$postfix" in 135 | "SHREC_2014_Real_viewListImage.txt" | "SHREC_2014_Synthetic_viewListImage.txt" ) 136 | nWords=1000 137 | ;; 138 | # "dl_test_viewListImage.txt" ) 139 | # nWords=1500 140 | # ;; 141 | "xie_data_viewListImage.txt" ) 142 | nWords=1000 143 | ;; 144 | esac 145 | 146 | prefix=${file%_*} 147 | $generateBow $file 1000 $prefix 148 | done 149 | # fi 150 | } 151 | 152 | generateObjFile 153 | generateLabelFile 154 | generateViews 155 | generateFeature 156 | 157 | exit 0 158 | -------------------------------------------------------------------------------- /multi_modality/set_env.sh: -------------------------------------------------------------------------------- 1 | DEEPNET_PATH=/home/cheng/work_shop/code/multi_modality/ 2 | 3 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DEEPNET_PATH/RBM/cudamat/:tools/ 4 | export PYTHONPATH=$DEEPNET_PATH:$DEEPNET_PATH/RBM/:$DEEPNET_PATH/RBM/cudamat/ 5 | 6 | -------------------------------------------------------------------------------- /multi_modality/tools/12_0.obj: -------------------------------------------------------------------------------- 1 | v 0.52573 0.38197 0.85065 2 | v -0.20081 0.61803 0.85065 3 | v -0.64984 0.00000 0.85065 4 | v -0.20081 -0.61803 0.85065 5 | v 0.52573 -0.38197 0.85065 6 | v 0.85065 -0.61803 0.20081 7 | v 1.0515 0.00000 -0.20081 8 | v 0.85065 0.61803 0.20081 9 | v 0.32492 1.00000 -0.20081 10 | v -0.32492 1.00000 0.20081 11 | v -0.85065 0.61803 -0.20081 12 | v -1.0515 0.00000 0.20081 13 | v -0.85065 -0.61803 -0.20081 14 | v -0.32492 -1.00000 0.20081 15 | v 0.32492 -1.00000 -0.20081 16 | v 0.64984 0.00000 -0.85065 17 | v 0.20081 0.61803 -0.85065 18 | v -0.52573 0.38197 -0.85065 19 | v -0.52573 -0.38197 -0.85065 20 | v 0.20081 -0.61803 -0.85065 21 | 22 | f 1 2 3 4 5 23 | f 1 5 6 7 8 24 | f 1 8 9 10 2 25 | f 2 10 11 12 3 26 | f 3 12 13 14 4 27 | f 14 15 6 5 4 28 | f 8 7 16 17 9 29 | f 10 9 17 18 11 30 | f 12 11 18 19 13 31 | f 14 13 19 20 15 32 | f 6 15 20 16 7 33 | f 17 16 20 19 18 -------------------------------------------------------------------------------- /multi_modality/tools/12_1.obj: -------------------------------------------------------------------------------- 1 | v 0.701802 0.689752 0.421444 2 | v 0.036426 0.714903 0.795914 3 | v -0.109796 0.014936 1.064716 4 | v 0.465216 -0.442823 0.856372 5 | v 0.966813 -0.025774 0.458810 6 | v 0.994836 -0.304541 -0.251889 7 | v 0.747181 0.238692 -0.728507 8 | v 0.566046 0.853184 -0.312347 9 | v -0.183238 0.979358 -0.391383 10 | v -0.510564 0.893894 0.293558 11 | v -0.994836 0.304541 0.251889 12 | v -0.747181 -0.238692 0.728507 13 | v -0.566046 -0.853184 0.312347 14 | v 0.183238 -0.979358 0.391383 15 | v 0.510564 -0.893894 -0.293558 16 | v 0.109796 -0.014936 -1.064716 17 | v -0.465216 0.442823 -0.856372 18 | v -0.966813 0.025774 -0.458810 19 | v -0.701802 -0.689752 -0.421444 20 | v -0.036426 -0.714903 -0.795914 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_2.obj: -------------------------------------------------------------------------------- 1 | v -0.265671 0.364304 0.970876 2 | v -0.889128 0.225538 0.551793 3 | v -0.875770 -0.509765 0.345058 4 | v -0.244050 -0.825444 0.636375 5 | v 0.133016 -0.285250 1.023151 6 | v 0.807144 -0.176679 0.680583 7 | v 0.825125 0.539979 0.416615 8 | v 0.162066 0.874304 0.596002 9 | v -0.197046 1.050748 -0.054765 10 | v -0.846719 0.649789 -0.082092 11 | v -0.807144 0.176679 -0.680583 12 | v -0.825125 -0.539979 -0.416615 13 | v -0.162066 -0.874304 -0.596002 14 | v 0.197046 -1.050748 0.054765 15 | v 0.846719 -0.649789 0.082092 16 | v 0.875770 0.509765 -0.345058 17 | v 0.244050 0.825444 -0.636375 18 | v -0.133016 0.285250 -1.023151 19 | v 0.265671 -0.364304 -0.970876 20 | v 0.889128 -0.225538 -0.551793 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_3.obj: -------------------------------------------------------------------------------- 1 | v 0.079042 0.242783 1.039571 2 | v -0.349675 0.756841 0.671425 3 | v -0.935122 0.387767 0.347966 4 | v -0.868230 -0.354398 0.516207 5 | v -0.241448 -0.444012 0.943639 6 | v 0.249304 -0.881208 0.554266 7 | v 0.873115 -0.464646 0.409574 8 | v 0.767860 0.230031 0.709484 9 | v 0.764860 0.736223 0.137338 10 | v 0.074186 1.061810 0.113812 11 | v -0.249304 0.881208 -0.554266 12 | v -0.873115 0.464646 -0.409574 13 | v -0.767860 -0.230031 -0.709484 14 | v -0.764860 -0.736223 -0.137338 15 | v -0.074186 -1.061810 -0.113812 16 | v 0.935122 -0.387767 -0.347966 17 | v 0.868230 0.354398 -0.516207 18 | v 0.241448 0.444012 -0.943639 19 | v -0.079042 -0.242783 -1.039571 20 | v 0.349675 -0.756841 -0.671425 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_4.obj: -------------------------------------------------------------------------------- 1 | v 0.041829 0.375558 1.001551 2 | v -0.620967 0.559182 0.669034 3 | v -0.965001 -0.088384 0.454818 4 | v -0.514823 -0.672232 0.654945 5 | v 0.107431 -0.385510 0.992844 6 | v 0.713218 -0.565332 0.563570 7 | v 1.022046 0.084586 0.306992 8 | v 0.607073 0.666081 0.577659 9 | v 0.293612 1.029275 -0.016836 10 | v -0.465359 0.963207 0.039633 11 | v -0.713218 0.565332 -0.563570 12 | v -1.022046 -0.084586 -0.306992 13 | v -0.607073 -0.666081 -0.577659 14 | v -0.293612 -1.029275 0.016836 15 | v 0.465359 -0.963207 -0.039633 16 | v 0.965001 0.088384 -0.454818 17 | v 0.514823 0.672232 -0.654945 18 | v -0.107431 0.385510 -0.992844 19 | v -0.041829 -0.375558 -1.001551 20 | v 0.620967 -0.559182 -0.669034 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_5.obj: -------------------------------------------------------------------------------- 1 | v 0.433241 -0.134526 0.969589 2 | v -0.274930 0.146734 1.024096 3 | v -0.750567 -0.343284 0.681691 4 | v -0.336349 -0.927398 0.415564 5 | v 0.395281 -0.798387 0.593489 6 | v 0.786987 -0.723306 -0.058062 7 | v 1.067072 -0.013062 -0.084644 8 | v 0.848406 0.350827 0.550471 9 | v 0.396820 0.932064 0.345960 10 | v -0.297441 0.805930 0.638673 11 | v -0.786987 0.723306 0.058062 12 | v -1.067072 0.013062 0.084644 13 | v -0.848406 -0.350827 -0.550471 14 | v -0.396820 -0.932064 -0.345960 15 | v 0.297441 -0.805930 -0.638673 16 | v 0.750567 0.343284 -0.681691 17 | v 0.336349 0.927398 -0.415564 18 | v -0.395281 0.798387 -0.593489 19 | v -0.433241 0.134526 -0.969589 20 | v 0.274930 -0.146734 -1.024096 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_6.obj: -------------------------------------------------------------------------------- 1 | v 0.620089 0.136630 0.861812 2 | v 0.051350 0.646547 0.851605 3 | v -0.609293 0.263137 0.839892 4 | v -0.448850 -0.483749 0.842859 5 | v 0.310944 -0.561943 0.856407 6 | v 0.524062 -0.909406 0.210311 7 | v 0.964951 -0.425608 -0.183589 8 | v 1.024262 0.220890 0.219057 9 | v 0.705320 0.782898 -0.188391 10 | v 0.104025 1.045970 0.202542 11 | v -0.524062 0.909406 -0.210311 12 | v -0.964951 0.425608 0.183589 13 | v -1.024262 -0.220890 -0.219057 14 | v -0.705320 -0.782898 0.188391 15 | v -0.104025 -1.045970 -0.202542 16 | v 0.609293 -0.263137 -0.839892 17 | v 0.448850 0.483749 -0.842859 18 | v -0.310944 0.561943 -0.856407 19 | v -0.620089 -0.136630 -0.861812 20 | v -0.051350 -0.646547 -0.851605 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_7.obj: -------------------------------------------------------------------------------- 1 | v 0.264391 -0.021073 1.037088 2 | v -0.493469 -0.057552 0.948192 3 | v -0.651797 -0.670655 0.520845 4 | v 0.008218 -1.013098 0.345625 5 | v 0.574455 -0.611642 0.664675 6 | v 1.011906 -0.333486 0.103555 7 | v 0.972243 0.428990 0.129183 8 | v 0.510220 0.622060 0.706122 9 | v -0.095718 0.983069 0.412688 10 | v -0.716033 0.563047 0.562292 11 | v -1.011906 0.333486 -0.103555 12 | v -0.972243 -0.428990 -0.129183 13 | v -0.510220 -0.622060 -0.706122 14 | v 0.095718 -0.983069 -0.412688 15 | v 0.716033 -0.563047 -0.562292 16 | v 0.651797 0.670655 -0.520845 17 | v -0.008218 1.013098 -0.345625 18 | v -0.574455 0.611642 -0.664675 19 | v -0.264391 0.021073 -1.037088 20 | v 0.493469 0.057552 -0.948192 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_8.obj: -------------------------------------------------------------------------------- 1 | v 0.254019 0.843500 0.608178 2 | v -0.492012 0.840739 0.443818 3 | v -0.787907 0.184936 0.700642 4 | v -0.224741 -0.217614 1.023732 5 | v 0.419205 0.189391 0.966590 6 | v 0.908089 -0.202376 0.529442 7 | v 1.045091 0.209604 -0.099130 8 | v 0.640819 0.855976 -0.050472 9 | v 0.133837 0.860940 -0.621906 10 | v -0.566293 0.851521 -0.316421 11 | v -0.908089 0.202376 -0.529442 12 | v -1.045091 -0.209604 0.099130 13 | v -0.640819 -0.855976 0.050472 14 | v -0.133837 -0.860940 0.621906 15 | v 0.566293 -0.851521 0.316421 16 | v 0.787907 -0.184936 -0.700642 17 | v 0.224741 0.217614 -1.023732 18 | v -0.419205 -0.189391 -0.966590 19 | v -0.254019 -0.843500 -0.608178 20 | v 0.492012 -0.840739 -0.443818 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/12_9.obj: -------------------------------------------------------------------------------- 1 | v 0.325105 0.556220 0.854883 2 | v -0.433545 0.466744 0.860279 3 | v -0.582969 -0.282387 0.852234 4 | v 0.083341 -0.655902 0.841866 5 | v 0.644563 -0.137625 0.843503 6 | v 1.032835 -0.208037 0.189380 7 | v 0.953383 0.442292 -0.203507 8 | v 0.515949 0.914609 0.207793 9 | v -0.124761 1.046644 -0.186731 10 | v -0.711583 0.769847 0.216524 11 | v -1.032835 0.208037 -0.189380 12 | v -0.953383 -0.442292 0.203507 13 | v -0.515949 -0.914609 -0.207793 14 | v 0.124761 -1.046644 0.186731 15 | v 0.711583 -0.769847 -0.216524 16 | v 0.582969 0.282387 -0.852234 17 | v -0.083341 0.655902 -0.841866 18 | v -0.644563 0.137625 -0.843503 19 | v -0.325105 -0.556220 -0.854883 20 | v 0.433545 -0.466744 -0.860279 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/tools/extractFeature: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/tools/extractFeature -------------------------------------------------------------------------------- /multi_modality/tools/genViewShapeData.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import numpy as np 3 | import os.path as path 4 | 5 | if __name__ == "__main__" : 6 | argv = sys.argv 7 | argc = len(argv); 8 | if argc != 3 : 9 | print "PARAMETER ERROR" 10 | print "usage : %s %s %s" % (argv[0], "viewBasedData", "shapeBasedData") 11 | sys.exit(-1) 12 | 13 | viewBasedData = np.load(argv[1]) 14 | shapeBasedData = np.load(argv[2]) 15 | jointData = np.append(viewBasedData, shapeBasedData, axis = 1) 16 | 17 | [baseName, fileName] = path.split(argv[1]) 18 | dataName = path.join(baseName, "viewShapeData.npy") 19 | np.save(dataName, jointData) 20 | 21 | -------------------------------------------------------------------------------- /multi_modality/tools/generateViews.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dirToSaveViewFeature=../data/viewFeatureData 3 | prog=./lfd.e 4 | 5 | #viewImgFileList=$(ls $dirToSaveViewFeature/*_viewListImage.txt) 6 | echo $viewImgFileList 7 | echo ${#viewImgFileList[@]} 8 | #if [ ${#viewImgFileList[@]}-1 -eq 0 ] 9 | #then 10 | 11 | for file in $(ls $dirToSaveViewFeature/*_objList.txt) 12 | do 13 | prefix=${file%_*} 14 | $prog $file $prefix"_labelIndex.txt" $prefix"_viewImage.txt" $prefix"_image" ./ 15 | 16 | done 17 | #fi 18 | 19 | -------------------------------------------------------------------------------- /multi_modality/tools/lfd.e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/tools/lfd.e -------------------------------------------------------------------------------- /multi_modality/tools/libcommon.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/tools/libcommon.so.1 -------------------------------------------------------------------------------- /multi_modality/tools/readShelve.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import shelve as sh 4 | import sys 5 | 6 | def readShelve(filename) : 7 | data = sh.open(filename) 8 | print data 9 | 10 | if __name__ == "__main__" : 11 | argc = len(sys.argv) 12 | if argc != 2 : 13 | print "Usage : %s",sys.argv[1], "filename" 14 | sys.exit(-1) 15 | 16 | readShelve(sys.argv[1]) 17 | -------------------------------------------------------------------------------- /multi_modality/tools/shapeNpyGen.py: -------------------------------------------------------------------------------- 1 | #/usr/bin python 2 | 3 | """using this when process shape feature""" 4 | 5 | import os 6 | import numpy as np 7 | import sys 8 | 9 | 10 | fileList = sys.argv[1] 11 | nShape = int(sys.argv[2]) 12 | nBow = int(sys.argv[3]) 13 | 14 | sep = "" 15 | 16 | # convert txt data format to npy format 17 | def collect() : 18 | fid = open(fileList,"r") 19 | shapePrefix = fid.readlines() 20 | 21 | nDim = int((1+nBow)*nBow*1.0/2) 22 | feature = np.zeros((nShape, nDim)) 23 | for index, line in enumerate(shapePrefix) : 24 | line = line.strip('\r\n') + "_ssbof.dat" 25 | print line 26 | temp = np.fromfile(line, dtype=np.float64, count=-1) 27 | temp = temp[1:] 28 | 29 | k = 0 30 | temp = temp.reshape(nBow,nBow) 31 | for i in range(nBow) : 32 | for j in range(i,nBow) : 33 | feature[index,k] = temp[i,j] 34 | k = k + 1 35 | 36 | (base, name) = os.path.split(fileList) 37 | pos = name.rfind('_') 38 | name = name[ : pos]+"_shapeBased_BOW.npy" 39 | featureName = os.path.join(base, name) 40 | np.save(featureName, feature) 41 | 42 | 43 | if __name__ == "__main__" : 44 | collect() 45 | -------------------------------------------------------------------------------- /multi_modality/tools/test_dir.e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/tools/test_dir.e -------------------------------------------------------------------------------- /multi_modality/tools/tools_meshsimplify.e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/tools/tools_meshsimplify.e -------------------------------------------------------------------------------- /multi_modality/tools/viewNpyGen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin python 2 | 3 | """convert feature data with txt format to npy format, including feature data labels 4 | use this when process view feature""" 5 | 6 | import numpy as np 7 | import os 8 | import sys 9 | 10 | dataPath = sys.argv[1] 11 | (prefix, featureData) = os.path.split(dataPath) 12 | nShape = int(sys.argv[2]) 13 | 14 | sep = " " 15 | 16 | def convert(): 17 | featureFileName = os.path.join(dataPath) 18 | feature = np.fromfile(featureFileName, dtype=np.float64, count=-1, sep=sep) 19 | feature = feature.reshape((nShape, -1)) 20 | 21 | label = feature[:, [0]] 22 | feature = feature[:, 2:] 23 | 24 | featureFileName = os.path.join(prefix, featureData.split('.')[0]+".npy") 25 | labelFileName = os.path.join(prefix, featureData.split('.')[0]+"_label.npy") 26 | np.save(featureFileName, feature) 27 | np.save(labelFileName, label) 28 | 29 | 30 | if __name__ == "__main__" : 31 | convert() 32 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_0.obj: -------------------------------------------------------------------------------- 1 | v 0.52573 0.38197 0.85065 2 | v -0.20081 0.61803 0.85065 3 | v -0.64984 0.00000 0.85065 4 | v -0.20081 -0.61803 0.85065 5 | v 0.52573 -0.38197 0.85065 6 | v 0.85065 -0.61803 0.20081 7 | v 1.0515 0.00000 -0.20081 8 | v 0.85065 0.61803 0.20081 9 | v 0.32492 1.00000 -0.20081 10 | v -0.32492 1.00000 0.20081 11 | v -0.85065 0.61803 -0.20081 12 | v -1.0515 0.00000 0.20081 13 | v -0.85065 -0.61803 -0.20081 14 | v -0.32492 -1.00000 0.20081 15 | v 0.32492 -1.00000 -0.20081 16 | v 0.64984 0.00000 -0.85065 17 | v 0.20081 0.61803 -0.85065 18 | v -0.52573 0.38197 -0.85065 19 | v -0.52573 -0.38197 -0.85065 20 | v 0.20081 -0.61803 -0.85065 21 | 22 | f 1 2 3 4 5 23 | f 1 5 6 7 8 24 | f 1 8 9 10 2 25 | f 2 10 11 12 3 26 | f 3 12 13 14 4 27 | f 14 15 6 5 4 28 | f 8 7 16 17 9 29 | f 10 9 17 18 11 30 | f 12 11 18 19 13 31 | f 14 13 19 20 15 32 | f 6 15 20 16 7 33 | f 17 16 20 19 18 -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_1.obj: -------------------------------------------------------------------------------- 1 | v 0.701802 0.689752 0.421444 2 | v 0.036426 0.714903 0.795914 3 | v -0.109796 0.014936 1.064716 4 | v 0.465216 -0.442823 0.856372 5 | v 0.966813 -0.025774 0.458810 6 | v 0.994836 -0.304541 -0.251889 7 | v 0.747181 0.238692 -0.728507 8 | v 0.566046 0.853184 -0.312347 9 | v -0.183238 0.979358 -0.391383 10 | v -0.510564 0.893894 0.293558 11 | v -0.994836 0.304541 0.251889 12 | v -0.747181 -0.238692 0.728507 13 | v -0.566046 -0.853184 0.312347 14 | v 0.183238 -0.979358 0.391383 15 | v 0.510564 -0.893894 -0.293558 16 | v 0.109796 -0.014936 -1.064716 17 | v -0.465216 0.442823 -0.856372 18 | v -0.966813 0.025774 -0.458810 19 | v -0.701802 -0.689752 -0.421444 20 | v -0.036426 -0.714903 -0.795914 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_2.obj: -------------------------------------------------------------------------------- 1 | v -0.265671 0.364304 0.970876 2 | v -0.889128 0.225538 0.551793 3 | v -0.875770 -0.509765 0.345058 4 | v -0.244050 -0.825444 0.636375 5 | v 0.133016 -0.285250 1.023151 6 | v 0.807144 -0.176679 0.680583 7 | v 0.825125 0.539979 0.416615 8 | v 0.162066 0.874304 0.596002 9 | v -0.197046 1.050748 -0.054765 10 | v -0.846719 0.649789 -0.082092 11 | v -0.807144 0.176679 -0.680583 12 | v -0.825125 -0.539979 -0.416615 13 | v -0.162066 -0.874304 -0.596002 14 | v 0.197046 -1.050748 0.054765 15 | v 0.846719 -0.649789 0.082092 16 | v 0.875770 0.509765 -0.345058 17 | v 0.244050 0.825444 -0.636375 18 | v -0.133016 0.285250 -1.023151 19 | v 0.265671 -0.364304 -0.970876 20 | v 0.889128 -0.225538 -0.551793 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_3.obj: -------------------------------------------------------------------------------- 1 | v 0.079042 0.242783 1.039571 2 | v -0.349675 0.756841 0.671425 3 | v -0.935122 0.387767 0.347966 4 | v -0.868230 -0.354398 0.516207 5 | v -0.241448 -0.444012 0.943639 6 | v 0.249304 -0.881208 0.554266 7 | v 0.873115 -0.464646 0.409574 8 | v 0.767860 0.230031 0.709484 9 | v 0.764860 0.736223 0.137338 10 | v 0.074186 1.061810 0.113812 11 | v -0.249304 0.881208 -0.554266 12 | v -0.873115 0.464646 -0.409574 13 | v -0.767860 -0.230031 -0.709484 14 | v -0.764860 -0.736223 -0.137338 15 | v -0.074186 -1.061810 -0.113812 16 | v 0.935122 -0.387767 -0.347966 17 | v 0.868230 0.354398 -0.516207 18 | v 0.241448 0.444012 -0.943639 19 | v -0.079042 -0.242783 -1.039571 20 | v 0.349675 -0.756841 -0.671425 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_4.obj: -------------------------------------------------------------------------------- 1 | v 0.041829 0.375558 1.001551 2 | v -0.620967 0.559182 0.669034 3 | v -0.965001 -0.088384 0.454818 4 | v -0.514823 -0.672232 0.654945 5 | v 0.107431 -0.385510 0.992844 6 | v 0.713218 -0.565332 0.563570 7 | v 1.022046 0.084586 0.306992 8 | v 0.607073 0.666081 0.577659 9 | v 0.293612 1.029275 -0.016836 10 | v -0.465359 0.963207 0.039633 11 | v -0.713218 0.565332 -0.563570 12 | v -1.022046 -0.084586 -0.306992 13 | v -0.607073 -0.666081 -0.577659 14 | v -0.293612 -1.029275 0.016836 15 | v 0.465359 -0.963207 -0.039633 16 | v 0.965001 0.088384 -0.454818 17 | v 0.514823 0.672232 -0.654945 18 | v -0.107431 0.385510 -0.992844 19 | v -0.041829 -0.375558 -1.001551 20 | v 0.620967 -0.559182 -0.669034 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_5.obj: -------------------------------------------------------------------------------- 1 | v 0.433241 -0.134526 0.969589 2 | v -0.274930 0.146734 1.024096 3 | v -0.750567 -0.343284 0.681691 4 | v -0.336349 -0.927398 0.415564 5 | v 0.395281 -0.798387 0.593489 6 | v 0.786987 -0.723306 -0.058062 7 | v 1.067072 -0.013062 -0.084644 8 | v 0.848406 0.350827 0.550471 9 | v 0.396820 0.932064 0.345960 10 | v -0.297441 0.805930 0.638673 11 | v -0.786987 0.723306 0.058062 12 | v -1.067072 0.013062 0.084644 13 | v -0.848406 -0.350827 -0.550471 14 | v -0.396820 -0.932064 -0.345960 15 | v 0.297441 -0.805930 -0.638673 16 | v 0.750567 0.343284 -0.681691 17 | v 0.336349 0.927398 -0.415564 18 | v -0.395281 0.798387 -0.593489 19 | v -0.433241 0.134526 -0.969589 20 | v 0.274930 -0.146734 -1.024096 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_6.obj: -------------------------------------------------------------------------------- 1 | v 0.620089 0.136630 0.861812 2 | v 0.051350 0.646547 0.851605 3 | v -0.609293 0.263137 0.839892 4 | v -0.448850 -0.483749 0.842859 5 | v 0.310944 -0.561943 0.856407 6 | v 0.524062 -0.909406 0.210311 7 | v 0.964951 -0.425608 -0.183589 8 | v 1.024262 0.220890 0.219057 9 | v 0.705320 0.782898 -0.188391 10 | v 0.104025 1.045970 0.202542 11 | v -0.524062 0.909406 -0.210311 12 | v -0.964951 0.425608 0.183589 13 | v -1.024262 -0.220890 -0.219057 14 | v -0.705320 -0.782898 0.188391 15 | v -0.104025 -1.045970 -0.202542 16 | v 0.609293 -0.263137 -0.839892 17 | v 0.448850 0.483749 -0.842859 18 | v -0.310944 0.561943 -0.856407 19 | v -0.620089 -0.136630 -0.861812 20 | v -0.051350 -0.646547 -0.851605 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_7.obj: -------------------------------------------------------------------------------- 1 | v 0.264391 -0.021073 1.037088 2 | v -0.493469 -0.057552 0.948192 3 | v -0.651797 -0.670655 0.520845 4 | v 0.008218 -1.013098 0.345625 5 | v 0.574455 -0.611642 0.664675 6 | v 1.011906 -0.333486 0.103555 7 | v 0.972243 0.428990 0.129183 8 | v 0.510220 0.622060 0.706122 9 | v -0.095718 0.983069 0.412688 10 | v -0.716033 0.563047 0.562292 11 | v -1.011906 0.333486 -0.103555 12 | v -0.972243 -0.428990 -0.129183 13 | v -0.510220 -0.622060 -0.706122 14 | v 0.095718 -0.983069 -0.412688 15 | v 0.716033 -0.563047 -0.562292 16 | v 0.651797 0.670655 -0.520845 17 | v -0.008218 1.013098 -0.345625 18 | v -0.574455 0.611642 -0.664675 19 | v -0.264391 0.021073 -1.037088 20 | v 0.493469 0.057552 -0.948192 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_8.obj: -------------------------------------------------------------------------------- 1 | v 0.254019 0.843500 0.608178 2 | v -0.492012 0.840739 0.443818 3 | v -0.787907 0.184936 0.700642 4 | v -0.224741 -0.217614 1.023732 5 | v 0.419205 0.189391 0.966590 6 | v 0.908089 -0.202376 0.529442 7 | v 1.045091 0.209604 -0.099130 8 | v 0.640819 0.855976 -0.050472 9 | v 0.133837 0.860940 -0.621906 10 | v -0.566293 0.851521 -0.316421 11 | v -0.908089 0.202376 -0.529442 12 | v -1.045091 -0.209604 0.099130 13 | v -0.640819 -0.855976 0.050472 14 | v -0.133837 -0.860940 0.621906 15 | v 0.566293 -0.851521 0.316421 16 | v 0.787907 -0.184936 -0.700642 17 | v 0.224741 0.217614 -1.023732 18 | v -0.419205 -0.189391 -0.966590 19 | v -0.254019 -0.843500 -0.608178 20 | v 0.492012 -0.840739 -0.443818 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/12_9.obj: -------------------------------------------------------------------------------- 1 | v 0.325105 0.556220 0.854883 2 | v -0.433545 0.466744 0.860279 3 | v -0.582969 -0.282387 0.852234 4 | v 0.083341 -0.655902 0.841866 5 | v 0.644563 -0.137625 0.843503 6 | v 1.032835 -0.208037 0.189380 7 | v 0.953383 0.442292 -0.203507 8 | v 0.515949 0.914609 0.207793 9 | v -0.124761 1.046644 -0.186731 10 | v -0.711583 0.769847 0.216524 11 | v -1.032835 0.208037 -0.189380 12 | v -0.953383 -0.442292 0.203507 13 | v -0.515949 -0.914609 -0.207793 14 | v 0.124761 -1.046644 0.186731 15 | v 0.711583 -0.769847 -0.216524 16 | v 0.582969 0.282387 -0.852234 17 | v -0.083341 0.655902 -0.841866 18 | v -0.644563 0.137625 -0.843503 19 | v -0.325105 -0.556220 -0.854883 20 | v 0.433545 -0.466744 -0.860279 21 | f 1 2 3 4 5 22 | f 1 5 6 7 8 23 | f 1 8 9 10 2 24 | f 2 10 11 12 3 25 | f 3 12 13 14 4 26 | f 14 15 6 5 4 27 | f 8 7 16 17 9 28 | f 10 9 17 18 11 29 | f 12 11 18 19 13 30 | f 14 13 19 20 15 31 | f 6 15 20 16 7 32 | f 17 16 20 19 18 33 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/Bitmap.cpp: -------------------------------------------------------------------------------- 1 | //#include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "Bitmap.h" 8 | 9 | 10 | using namespace cv; 11 | 12 | // the input "Buff" has "no" pad after every row 13 | // so, it must add "pad" after every row 14 | void WriteBitmap(unsigned char *Buff, int x, int y, char *filename) 15 | { 16 | Mat img; 17 | unsigned char *p1, *p2; 18 | int i; 19 | 20 | img.create(y, x, CV_8UC3); 21 | p2 = img.data; 22 | p1 = Buff; 23 | 24 | for(i=0; i<3*x*y; i++) p2[i] = p1[i]; 25 | 26 | imwrite(filename, img); 27 | } 28 | 29 | void WriteBitmap8(unsigned char *sBuff, int x, int y, char *filename) 30 | { 31 | Mat img; 32 | unsigned char *p1, *p2; 33 | int i; 34 | 35 | img.create(y, x, CV_8UC1); 36 | p2 = img.data; 37 | p1 = sBuff; 38 | 39 | for(i=0; i0 ) 35 | { 36 | cir = PI4 * A / ( p * p ); 37 | if( cir > 1 ) 38 | cir = 1; 39 | } 40 | else 41 | cir = 0; // if render nothing (bad) 42 | 43 | return cir; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/Circularity.h: -------------------------------------------------------------------------------- 1 | double Circularity(unsigned char *srcBuff, int width, int height, unsigned char *edge); 2 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/ColorDescriptor.h: -------------------------------------------------------------------------------- 1 | #include "win_types.h" 2 | 3 | void ColorHistogram(double *HistogramValue, unsigned char *yuvBuff, int width, int height); 4 | void CompactColor(unsigned char *CompactValue, double *HistogramValue); 5 | void ExtractCCD(unsigned char *YuvBuff, uint64_t *CCD, unsigned char *SrcBuff); 6 | double ColorDistance(uint64_t *dest, uint64_t *src); 7 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/CompactColor.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/viewFeatrueExtract/3DAlignmentCode/CompactColor.c -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/Convert.c: -------------------------------------------------------------------------------- 1 | #include "Ds.h" 2 | 3 | void RGB_To_YUV(unsigned char *yuvBuff, unsigned char *rgbBuff, int width, int height) 4 | { 5 | 6 | int i, j, total, width3; 7 | 8 | width3 = 3 * width; 9 | total = width3 * height; 10 | for(i=0; i 2 | #define POW2(a) ((a)*(a)) 3 | 4 | double Eccentricity(unsigned char *srcBuff, int width, int height, double CenX, double CenY) 5 | { 6 | int x, y, count; 7 | unsigned char *pImage; 8 | double i11, i02, i20; 9 | double ecc; 10 | 11 | count = 0; 12 | pImage = srcBuff; 13 | i11 = i02 = i20 = 0; 14 | for (y=0 ; y 1 ) 28 | { 29 | // defined in MPEG-7, seen not good 30 | // dtmp = sqrt( POW2(i20-i02) + 4 * POW2(i11) ); 31 | // if( (i20+i02-dtmp) > 0 ) 32 | // return sqrt( (i20+i02+dtmp) / (i20+i02-dtmp) ); 33 | // else 34 | // return 1.0; 35 | 36 | // defined in other paper 37 | ecc = ( POW2(i20-i02) + 4 * POW2(i11) ) / POW2(i20+i02); 38 | if( ecc > 1 ) 39 | ecc = 1; 40 | } 41 | else 42 | ecc = 0; 43 | 44 | return ecc; 45 | } 46 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/Eccentricity.h: -------------------------------------------------------------------------------- 1 | double Eccentricity(unsigned char *srcBuff, int width, int height, double CenX, double CenY); 2 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/Edge.h: -------------------------------------------------------------------------------- 1 | void EdgeDetect(unsigned char *dest, unsigned char *src, int width, int height); 2 | void EdgeDetectSil(unsigned char *edge, unsigned char *src, int width, int height); 3 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/FourierDescriptor.h: -------------------------------------------------------------------------------- 1 | #include "Ds.h" 2 | 3 | void FourierDescriptor(double FdCoeff[], unsigned char *Y, int width, int height, sPOINT *Contour, unsigned char *ContourMask, double CenX, double CenY); 4 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/MORPHOLOGY.H: -------------------------------------------------------------------------------- 1 | #ifndef __MORPHOLOGY_H__ 2 | #define __MORPHOLOGY_H__ 3 | 4 | #include "win_types.h" 5 | 6 | void BINARYDilation(BYTE *r, POINT ImageSize, int MaskNum, POINT *MaskCoor); 7 | void BINARYDilation3x3(BYTE *r, POINT ImageSize); 8 | void BINARYDilation5x5(BYTE *r, POINT ImageSize); 9 | void BINARYErosion(BYTE *r, POINT ImageSize, int MaskNum, POINT *MaskCoor); 10 | void BINARYErosion3x3(BYTE *r, POINT ImageSize); 11 | void BINARYErosion5x5(BYTE *r, POINT ImageSize); 12 | void BINARYOpening3x3(BYTE *r, POINT ImageSize); 13 | void BINARYOpening5x5(BYTE *r, POINT ImageSize); 14 | void BINARYClosing3x3(BYTE *r, POINT ImageSize); 15 | void BINARYClosing5x5(BYTE *r, POINT ImageSize); 16 | void BINARYHit_and_Miss(BYTE *r, POINT ImageSize, POINT *HitMask, int HitMaskNum, POINT *MissMask, int MissMaskNum); 17 | void BINARYHit_and_Miss_TopRightCorner(BYTE *r, POINT ImageSize); 18 | void BINARYHit_and_Miss_BottomLeftCorner(BYTE *r, POINT ImageSize); 19 | void GRAYSCALEDilation(BYTE *r, POINT ImageSize, int MaskNum, POINT *MaskCoor, int *MaskValue); 20 | void GRAYSCALEDilation3x3(BYTE *r, POINT ImageSize); 21 | void GRAYSCALEDilation5x5(BYTE *r, POINT ImageSize); 22 | void GRAYSCALEErosion(BYTE *r, POINT ImageSize, int MaskNum, POINT *MaskCoor, int *MaskValue); 23 | void GRAYSCALEErosion3x3(BYTE *r, POINT ImageSize); 24 | void GRAYSCALEErosion5x5(BYTE *r, POINT ImageSize); 25 | void GRAYSCALEOpening3x3(BYTE *r, POINT ImageSize); 26 | void GRAYSCALEOpening5x5(BYTE *r, POINT ImageSize); 27 | void GRAYSCALEClosing3x3(BYTE *r, POINT ImageSize); 28 | void GRAYSCALEClosing5x5(BYTE *r, POINT ImageSize); 29 | unsigned char BoundingBox(unsigned char *mY, POINT Size); 30 | 31 | #endif // end of __MORPHOLOGY_H__ 32 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CXX=g++ 3 | 4 | ################################################################################ 5 | # OpenCV settings 6 | # run following command first: 7 | # EXPORT PKG_CONFIG_PATH=/opt/OpenCV-2.4/lib/pkgconfig 8 | ################################################################################ 9 | OPENCV_CFLAGS = $(shell pkg-config --cflags opencv) 10 | OPENCV_LIBS = $(shell pkg-config --libs opencv) 11 | 12 | ################################################################################ 13 | # OpenGL settings 14 | ################################################################################ 15 | OPENGL_CFLAGS = 16 | OPENGL_LIBS = -lGL -lGLU -lglut 17 | 18 | ################################################################################ 19 | # FFTW settings 20 | ################################################################################ 21 | FFTW_CFLAGS = -I./fftw 22 | FFTW_LIBS = -L./fftw -lfftw 23 | 24 | 25 | ################################################################################ 26 | # Overall settings 27 | ################################################################################ 28 | ALL_CFLAGS = $(OPENCV_CFLAGS) $(OPENGL_CFLAGS) $(FFTW_CFLAGS) 29 | ALL_LIBS = $(OPENCV_LIBS) $(OPENGL_LIBS) $(FFTW_LIBS) 30 | 31 | 32 | src-cxx-all := $(wildcard *.cpp) 33 | src-c-all := $(wildcard *.c) 34 | bin-all := $(patsubst %.cpp,%.e,$(src-cxx-all)) $(patsubst %.c,%.e,$(src-c-all)) 35 | obj-all := $(patsubst %.cpp,%.o,$(src-cxx-all)) $(patsubst %.c,%.o,$(src-c-all)) 36 | 37 | 38 | 39 | all : lfd.e 40 | 41 | lfd.e : $(obj-all) 42 | $(CXX) -o $@ $? $(ALL_LIBS) 43 | 44 | %.e:%.cpp 45 | $(CXX) $< -g -o $@ $(ALL_CFLAGS) $(ALL_LIBS) 46 | 47 | %.e:%.c 48 | $(CXX) $< -g -o $@ $(ALL_CFLAGS) $(ALL_LIBS) 49 | 50 | %.o:%.cpp 51 | $(CXX) -g -c $< -o $@ $(ALL_CFLAGS) 52 | 53 | %.o:%.c 54 | $(CXX) -g -c $< -o $@ $(ALL_CFLAGS) 55 | 56 | clean : 57 | rm -f *.e *.o 58 | 59 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/RWObj.h: -------------------------------------------------------------------------------- 1 | #include "Ds.h" 2 | 3 | int ReadObj(char *filename, pVer *vertex, pTri *triangle, int *NumVer, int *NumTri); 4 | void SaveObj(char *filename, pVer vertex, pTri triangle, int NumVer, int NumTri); 5 | void SaveMergeObj(char *filename, pVer vertex1, pTri triangle1, int NumVer1, int NumTri1, 6 | pVer vertex2, pTri triangle2, int NumVer2, int NumTri2); 7 | int ReadData(char *filename, pVer *vertex, pTri *triangle, int *NumVer, int *NumTri); 8 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/RecovAffine.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "win_types.h" 6 | #include "Ds.h" 7 | #include "RWObj.h" 8 | #include "Rotate.h" 9 | 10 | extern char srcfn[]; 11 | extern char destfn[]; 12 | 13 | double RecoverAffine(double **matrix, double cost[ANGLE][ANGLE][CAMNUM_2][CAMNUM_2], int *MinSrcCam) 14 | { 15 | double err, MinErr; 16 | int align[60][20], i, j, k, angle, index, srcCam; 17 | FILE *fpt; 18 | char filename[100]; 19 | pVer VerRot; 20 | pTri TriRot; 21 | int NumVerRot, NumTriRot; 22 | vector e1[2], e2[2]; // coordinate of edge 23 | 24 | // read align sequence 25 | fpt = fopen("align20.txt", "r"); 26 | for(i=0; i<60; i++) 27 | for(j=0; j 2 | #include 3 | 4 | #include "win_types.h" 5 | #include "Bitmap.h" 6 | #include "Ds.h" 7 | 8 | int GetStart(unsigned char *Y, int width, int height) 9 | { 10 | unsigned char *pY, *total = Y + width * height; 11 | 12 | for(pY=Y; pY < total; pY++) 13 | if( *pY < 255 ) 14 | return pY-Y; 15 | 16 | return -1; 17 | } 18 | 19 | // input is a 1D array 20 | // the boundary of the input image should be white (background) to avoid overflow 21 | int TraceContour(sPOINT *Contour, unsigned char *ContourMask, unsigned char *Y, int width, int height) 22 | { 23 | // dirP[0~3] denote down, right, up, left 24 | // dirP[x][0~2] denote P1, P2 and P3 25 | int nextPos[4][3] = { {width-1, width, width+1}, {width+1, 1, -width+1}, 26 | {-width+1, -width, -width-1}, {-width-1, -1, width-1}}; 27 | int nextDir[4][3] = { {3,0,0}, {0,1,1}, {1,2,2}, {2,3,3}}; 28 | 29 | int curPos, curDir; 30 | int i, j, start, walk, mayLoss; 31 | int count; 32 | 33 | if( (start = GetStart(Y, width, height)) < 0 ) 34 | return -1; // error, no pixel exists 35 | 36 | // there are three case may miss some part (b: background; s: start point; v: foreground) 37 | // b b b b b b b b b 38 | // b s b b s v b s v 39 | // v b v v b b v b v 40 | // and there are no cicle from left 'v' to right 'v' 41 | // set mayLoss=1 if in one of the three case 42 | if( Y[start+width-1]<255 && Y[start+width]==255 && (Y[start+width+1]<255 || Y[start+1]<255 ) ) 43 | mayLoss = 1; 44 | else 45 | mayLoss = 0; 46 | 47 | curPos = start; 48 | curDir = 0; // initially, face down 49 | 50 | count = 0; 51 | 52 | Contour[count].x = curPos%width; 53 | Contour[count].y = curPos/width; 54 | memset(ContourMask, 0, width*height * sizeof(unsigned char)); 55 | ContourMask[curPos] = 255; // the pixel is contour 56 | count ++; 57 | 58 | while(1) 59 | { 60 | walk = 0; 61 | for(j=0; j<4; j++) 62 | { 63 | for(i=0; i<3; i++) 64 | if( Y[ curPos + nextPos[curDir][i] ] < 255 ) 65 | { 66 | curPos += nextPos[curDir][i]; 67 | curDir = nextDir[curDir][i]; 68 | 69 | Contour[count].x = curPos%width; 70 | Contour[count].y = curPos/width; 71 | ContourMask[curPos] = 255; // the pixel is contour 72 | count ++; 73 | 74 | walk = 1; 75 | break; 76 | } 77 | 78 | if(walk == 1) 79 | break; 80 | 81 | curDir = (curDir+1) % 4 ; 82 | } 83 | 84 | if( walk == 0 ) 85 | return -1; // isolated pixel, return error 86 | 87 | // if the three case and the last return is left (curDir=3), then go to right part 88 | if(curPos == start && ( mayLoss!=1 || curDir!=1 ) ) 89 | return count; // success 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/TraceContour.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRACECONTOUR_H__ 2 | #define __TRACECONTOUR_H__ 3 | 4 | #include "Ds.h" 5 | 6 | int TraceContour(sPOINT *Contour, unsigned char *ContourMask, unsigned char *Y, int width, int height); 7 | 8 | #endif // end of __TRACECONTOUR_H__ 9 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/TranslateScale.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "win_types.h" 8 | #include "Ds.h" 9 | #include "RWObj.h" 10 | 11 | double max(double a, double b, double c) 12 | { 13 | double d = (a>b)?a:b; 14 | return (c>d)?c:d; 15 | } 16 | 17 | void TranslateScale(pVer vertex, int NumVer, pTri triangle, int NumTri, char *fn, pVer T, double *S) 18 | { 19 | Ver Translate; 20 | double scale, dtmp; 21 | // FILE *fpt; 22 | // char filename[100]; 23 | int i, j, k; 24 | Ver MinCoor, MaxCoor; 25 | 26 | // if vertices didn't use in any face, don't include it 27 | 28 | // get minimum and maximum coornidate from 3D model 29 | for(k=0; k<3; k++) 30 | { 31 | MinCoor.coor[k] = DBL_MAX; 32 | MaxCoor.coor[k] = -DBL_MAX; 33 | } 34 | for(i=0; i MaxCoor.coor[k] ) 42 | MaxCoor.coor[k] = dtmp; 43 | } 44 | 45 | // get the translate and scale 46 | Translate.coor[0] = -( MinCoor.coor[0] + MaxCoor.coor[0] ) / 2; 47 | Translate.coor[1] = -( MinCoor.coor[1] + MaxCoor.coor[1] ) / 2; 48 | Translate.coor[2] = -( MinCoor.coor[2] + MaxCoor.coor[2] ) / 2; 49 | scale = 1.0 / max( MaxCoor.coor[0]-MinCoor.coor[0], 50 | MaxCoor.coor[1]-MinCoor.coor[1], 51 | MaxCoor.coor[2]-MinCoor.coor[2]); 52 | 53 | /* // save the center and scale paramater 54 | sprintf(filename, "%s_TS.txt", fn); 55 | fpt = fopen(filename, "w"); 56 | fprintf(fpt, "%f %f %f\n%.12f\n", Translate.coor[0], Translate.coor[1], Translate.coor[2], scale); 57 | fclose(fpt); 58 | */ 59 | 60 | // translate and scale 3D model 61 | for(i=0; icoor[0] = Translate.coor[0]; 70 | T->coor[1] = Translate.coor[1]; 71 | T->coor[2] = Translate.coor[2]; 72 | *S = scale; 73 | 74 | // sprintf(filename, "%s_ts.obj", srcfn); 75 | // SaveObj(filename, vertex, triangle, NumVer, NumTri); 76 | } 77 | 78 | void Translate(pVer vertex, int NumVer, Ver Translate) 79 | { 80 | int i, j; 81 | 82 | for(i=0; i 2 | #include 3 | #include 4 | 5 | typedef struct POINT_ 6 | { 7 | int x, y; 8 | }POINT; 9 | 10 | int MaskValue(unsigned char *r, POINT ImageSize, int j, int k, int l, int MaskNum, POINT *MaskCoor, float *MaskWeight) 11 | { 12 | int i; 13 | float tmp; 14 | 15 | tmp = 0.0f; 16 | for(i=0; ix>=0 && k+(MaskCoor+i)->xy>=0 && l+(MaskCoor+i)->yy)*ImageSize.x+k+(MaskCoor+i)->x); 21 | else 22 | tmp += *(MaskWeight+i) * *(r+j+k); 23 | } 24 | 25 | return (int)(tmp+0.5); 26 | } 27 | 28 | void GRAYSCALEEdgeSobel(unsigned char *dest, unsigned char *src, POINT ImageSize) 29 | { 30 | int TotalSize = ImageSize.x * ImageSize.y; 31 | int j, k, l; 32 | int x, y; 33 | int tmp; 34 | // -1 1 35 | // -2 < > 2 36 | // -1 1 37 | POINT MaskCoor1[6]={ 38 | {-1,-1} , {-1,1} , 39 | {0,-1} , {0,1} , 40 | {1,-1} , {1,1} 41 | }; 42 | float MaskWeight1[6] = {-1.0f,1.0f,-2.0f,2.0f,-1.0f,1.0f}; 43 | // -1 -2 -1 44 | // < > 45 | // 1 2 1 46 | POINT MaskCoor2[6]={ 47 | {-1,-1} , {-1,0} , {-1,1} , 48 | {1,-1} , {1,0} , {1,1} 49 | }; 50 | float MaskWeight2[6] = {-1.0f,-2.0f,-1.0f,1.0f,2.0f,1.0f}; 51 | 52 | for(j=0, l=0; j255) 59 | tmp = 255; 60 | *(dest+j+k) = tmp; 61 | } 62 | } 63 | 64 | // test edge from depth 65 | void EdgeDetect(unsigned char *dest, unsigned char *src, int width, int height) 66 | { 67 | POINT ImageSize; 68 | ImageSize.x = width; 69 | ImageSize.y = height; 70 | GRAYSCALEEdgeSobel(dest, src, ImageSize); 71 | } 72 | 73 | // test edge from silhouette 74 | void EdgeDetectSil(unsigned char *edge, unsigned char *src, int width, int height) 75 | { 76 | int TotalSize = width * height; 77 | int j, k, l; 78 | 79 | for(j=0, l=0; j0 && *(src+j+k-width) == 255 ) 88 | *(edge+j+k) = 0; // edge 89 | if( k>0 && *(src+j+k-1) == 255 ) 90 | *(edge+j+k) = 0; // edge 91 | if( l0 && k>0 && *(src+j+k-width-1) == 255 ) 97 | *(edge+j+k) = 0; // edge 98 | if( l>0 && k0 && *(src+j+k+width-1) == 255 ) 101 | *(edge+j+k) = 0; // edge 102 | if( l 0; i = i - 1, inout = inout + dist, W = W + 1) { 47 | fftw_real tmp1; 48 | fftw_real tmp8; 49 | fftw_real tmp6; 50 | fftw_real tmp7; 51 | ASSERT_ALIGNED_DOUBLE; 52 | tmp1 = c_re(inout[0]); 53 | tmp8 = c_im(inout[0]); 54 | { 55 | fftw_real tmp3; 56 | fftw_real tmp5; 57 | fftw_real tmp2; 58 | fftw_real tmp4; 59 | ASSERT_ALIGNED_DOUBLE; 60 | tmp3 = c_re(inout[iostride]); 61 | tmp5 = c_im(inout[iostride]); 62 | tmp2 = c_re(W[0]); 63 | tmp4 = c_im(W[0]); 64 | tmp6 = (tmp2 * tmp3) - (tmp4 * tmp5); 65 | tmp7 = (tmp4 * tmp3) + (tmp2 * tmp5); 66 | } 67 | c_re(inout[iostride]) = tmp1 - tmp6; 68 | c_re(inout[0]) = tmp1 + tmp6; 69 | c_im(inout[0]) = tmp7 + tmp8; 70 | c_im(inout[iostride]) = tmp8 - tmp7; 71 | } 72 | } 73 | 74 | static const int twiddle_order[] = 75 | {1}; 76 | fftw_codelet_desc fftw_twiddle_2_desc = 77 | { 78 | "fftw_twiddle_2", 79 | (void (*)()) fftw_twiddle_2, 80 | 2, 81 | FFTW_FORWARD, 82 | FFTW_TWIDDLE, 83 | 44, 84 | 1, 85 | twiddle_order, 86 | }; 87 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/fftw/ftw_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | /* This file was automatically generated --- DO NOT EDIT */ 21 | /* Generated on Sun Nov 7 20:44:30 EST 1999 */ 22 | 23 | #include "fftw-int.h" 24 | #include "fftw.h" 25 | 26 | /* Generated by: ./genfft -magic-alignment-check -magic-twiddle-load-all -magic-variables 4 -magic-loopi -twiddle 3 */ 27 | 28 | /* 29 | * This function contains 16 FP additions, 12 FP multiplications, 30 | * (or, 10 additions, 6 multiplications, 6 fused multiply/add), 31 | * 14 stack variables, and 12 memory accesses 32 | */ 33 | static const fftw_real K866025403 = FFTW_KONST(+0.866025403784438646763723170752936183471402627); 34 | static const fftw_real K500000000 = FFTW_KONST(+0.500000000000000000000000000000000000000000000); 35 | 36 | /* 37 | * Generator Id's : 38 | * $Id: exprdag.ml,v 1.41 1999/05/26 15:44:14 fftw Exp $ 39 | * $Id: fft.ml,v 1.43 1999/05/17 19:44:18 fftw Exp $ 40 | * $Id: to_c.ml,v 1.25 1999/10/26 21:41:32 stevenj Exp $ 41 | */ 42 | 43 | void fftw_twiddle_3(fftw_complex *A, const fftw_complex *W, int iostride, int m, int dist) 44 | { 45 | int i; 46 | fftw_complex *inout; 47 | inout = A; 48 | for (i = m; i > 0; i = i - 1, inout = inout + dist, W = W + 2) { 49 | fftw_real tmp1; 50 | fftw_real tmp18; 51 | fftw_real tmp6; 52 | fftw_real tmp14; 53 | fftw_real tmp11; 54 | fftw_real tmp15; 55 | fftw_real tmp12; 56 | fftw_real tmp17; 57 | ASSERT_ALIGNED_DOUBLE; 58 | tmp1 = c_re(inout[0]); 59 | tmp18 = c_im(inout[0]); 60 | { 61 | fftw_real tmp3; 62 | fftw_real tmp5; 63 | fftw_real tmp2; 64 | fftw_real tmp4; 65 | ASSERT_ALIGNED_DOUBLE; 66 | tmp3 = c_re(inout[iostride]); 67 | tmp5 = c_im(inout[iostride]); 68 | tmp2 = c_re(W[0]); 69 | tmp4 = c_im(W[0]); 70 | tmp6 = (tmp2 * tmp3) - (tmp4 * tmp5); 71 | tmp14 = (tmp4 * tmp3) + (tmp2 * tmp5); 72 | } 73 | { 74 | fftw_real tmp8; 75 | fftw_real tmp10; 76 | fftw_real tmp7; 77 | fftw_real tmp9; 78 | ASSERT_ALIGNED_DOUBLE; 79 | tmp8 = c_re(inout[2 * iostride]); 80 | tmp10 = c_im(inout[2 * iostride]); 81 | tmp7 = c_re(W[1]); 82 | tmp9 = c_im(W[1]); 83 | tmp11 = (tmp7 * tmp8) - (tmp9 * tmp10); 84 | tmp15 = (tmp9 * tmp8) + (tmp7 * tmp10); 85 | } 86 | tmp12 = tmp6 + tmp11; 87 | tmp17 = tmp14 + tmp15; 88 | { 89 | fftw_real tmp13; 90 | fftw_real tmp16; 91 | fftw_real tmp19; 92 | fftw_real tmp20; 93 | ASSERT_ALIGNED_DOUBLE; 94 | c_re(inout[0]) = tmp1 + tmp12; 95 | tmp13 = tmp1 - (K500000000 * tmp12); 96 | tmp16 = K866025403 * (tmp14 - tmp15); 97 | c_re(inout[2 * iostride]) = tmp13 - tmp16; 98 | c_re(inout[iostride]) = tmp13 + tmp16; 99 | c_im(inout[0]) = tmp17 + tmp18; 100 | tmp19 = K866025403 * (tmp11 - tmp6); 101 | tmp20 = tmp18 - (K500000000 * tmp17); 102 | c_im(inout[iostride]) = tmp19 + tmp20; 103 | c_im(inout[2 * iostride]) = tmp20 - tmp19; 104 | } 105 | } 106 | } 107 | 108 | static const int twiddle_order[] = 109 | {1, 2}; 110 | fftw_codelet_desc fftw_twiddle_3_desc = 111 | { 112 | "fftw_twiddle_3", 113 | (void (*)()) fftw_twiddle_3, 114 | 3, 115 | FFTW_FORWARD, 116 | FFTW_TWIDDLE, 117 | 66, 118 | 2, 119 | twiddle_order, 120 | }; 121 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/fftw/ftwi_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | /* This file was automatically generated --- DO NOT EDIT */ 21 | /* Generated on Sun Nov 7 20:44:57 EST 1999 */ 22 | 23 | #include "fftw-int.h" 24 | #include "fftw.h" 25 | 26 | /* Generated by: ./genfft -magic-alignment-check -magic-twiddle-load-all -magic-variables 4 -magic-loopi -twiddleinv 2 */ 27 | 28 | /* 29 | * This function contains 6 FP additions, 4 FP multiplications, 30 | * (or, 4 additions, 2 multiplications, 2 fused multiply/add), 31 | * 10 stack variables, and 8 memory accesses 32 | */ 33 | 34 | /* 35 | * Generator Id's : 36 | * $Id: exprdag.ml,v 1.41 1999/05/26 15:44:14 fftw Exp $ 37 | * $Id: fft.ml,v 1.43 1999/05/17 19:44:18 fftw Exp $ 38 | * $Id: to_c.ml,v 1.25 1999/10/26 21:41:32 stevenj Exp $ 39 | */ 40 | 41 | void fftwi_twiddle_2(fftw_complex *A, const fftw_complex *W, int iostride, int m, int dist) 42 | { 43 | int i; 44 | fftw_complex *inout; 45 | inout = A; 46 | for (i = m; i > 0; i = i - 1, inout = inout + dist, W = W + 1) { 47 | fftw_real tmp1; 48 | fftw_real tmp8; 49 | fftw_real tmp6; 50 | fftw_real tmp7; 51 | ASSERT_ALIGNED_DOUBLE; 52 | tmp1 = c_re(inout[0]); 53 | tmp8 = c_im(inout[0]); 54 | { 55 | fftw_real tmp3; 56 | fftw_real tmp5; 57 | fftw_real tmp2; 58 | fftw_real tmp4; 59 | ASSERT_ALIGNED_DOUBLE; 60 | tmp3 = c_re(inout[iostride]); 61 | tmp5 = c_im(inout[iostride]); 62 | tmp2 = c_re(W[0]); 63 | tmp4 = c_im(W[0]); 64 | tmp6 = (tmp2 * tmp3) + (tmp4 * tmp5); 65 | tmp7 = (tmp2 * tmp5) - (tmp4 * tmp3); 66 | } 67 | c_re(inout[iostride]) = tmp1 - tmp6; 68 | c_re(inout[0]) = tmp1 + tmp6; 69 | c_im(inout[0]) = tmp7 + tmp8; 70 | c_im(inout[iostride]) = tmp8 - tmp7; 71 | } 72 | } 73 | 74 | static const int twiddle_order[] = 75 | {1}; 76 | fftw_codelet_desc fftwi_twiddle_2_desc = 77 | { 78 | "fftwi_twiddle_2", 79 | (void (*)()) fftwi_twiddle_2, 80 | 2, 81 | FFTW_BACKWARD, 82 | FFTW_TWIDDLE, 83 | 55, 84 | 1, 85 | twiddle_order, 86 | }; 87 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/fftw/ftwi_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | /* This file was automatically generated --- DO NOT EDIT */ 21 | /* Generated on Sun Nov 7 20:44:57 EST 1999 */ 22 | 23 | #include "fftw-int.h" 24 | #include "fftw.h" 25 | 26 | /* Generated by: ./genfft -magic-alignment-check -magic-twiddle-load-all -magic-variables 4 -magic-loopi -twiddleinv 3 */ 27 | 28 | /* 29 | * This function contains 16 FP additions, 12 FP multiplications, 30 | * (or, 10 additions, 6 multiplications, 6 fused multiply/add), 31 | * 14 stack variables, and 12 memory accesses 32 | */ 33 | static const fftw_real K866025403 = FFTW_KONST(+0.866025403784438646763723170752936183471402627); 34 | static const fftw_real K500000000 = FFTW_KONST(+0.500000000000000000000000000000000000000000000); 35 | 36 | /* 37 | * Generator Id's : 38 | * $Id: exprdag.ml,v 1.41 1999/05/26 15:44:14 fftw Exp $ 39 | * $Id: fft.ml,v 1.43 1999/05/17 19:44:18 fftw Exp $ 40 | * $Id: to_c.ml,v 1.25 1999/10/26 21:41:32 stevenj Exp $ 41 | */ 42 | 43 | void fftwi_twiddle_3(fftw_complex *A, const fftw_complex *W, int iostride, int m, int dist) 44 | { 45 | int i; 46 | fftw_complex *inout; 47 | inout = A; 48 | for (i = m; i > 0; i = i - 1, inout = inout + dist, W = W + 2) { 49 | fftw_real tmp1; 50 | fftw_real tmp18; 51 | fftw_real tmp6; 52 | fftw_real tmp15; 53 | fftw_real tmp11; 54 | fftw_real tmp14; 55 | fftw_real tmp12; 56 | fftw_real tmp17; 57 | ASSERT_ALIGNED_DOUBLE; 58 | tmp1 = c_re(inout[0]); 59 | tmp18 = c_im(inout[0]); 60 | { 61 | fftw_real tmp3; 62 | fftw_real tmp5; 63 | fftw_real tmp2; 64 | fftw_real tmp4; 65 | ASSERT_ALIGNED_DOUBLE; 66 | tmp3 = c_re(inout[iostride]); 67 | tmp5 = c_im(inout[iostride]); 68 | tmp2 = c_re(W[0]); 69 | tmp4 = c_im(W[0]); 70 | tmp6 = (tmp2 * tmp3) + (tmp4 * tmp5); 71 | tmp15 = (tmp2 * tmp5) - (tmp4 * tmp3); 72 | } 73 | { 74 | fftw_real tmp8; 75 | fftw_real tmp10; 76 | fftw_real tmp7; 77 | fftw_real tmp9; 78 | ASSERT_ALIGNED_DOUBLE; 79 | tmp8 = c_re(inout[2 * iostride]); 80 | tmp10 = c_im(inout[2 * iostride]); 81 | tmp7 = c_re(W[1]); 82 | tmp9 = c_im(W[1]); 83 | tmp11 = (tmp7 * tmp8) + (tmp9 * tmp10); 84 | tmp14 = (tmp7 * tmp10) - (tmp9 * tmp8); 85 | } 86 | tmp12 = tmp6 + tmp11; 87 | tmp17 = tmp15 + tmp14; 88 | { 89 | fftw_real tmp13; 90 | fftw_real tmp16; 91 | fftw_real tmp19; 92 | fftw_real tmp20; 93 | ASSERT_ALIGNED_DOUBLE; 94 | c_re(inout[0]) = tmp1 + tmp12; 95 | tmp13 = tmp1 - (K500000000 * tmp12); 96 | tmp16 = K866025403 * (tmp14 - tmp15); 97 | c_re(inout[2 * iostride]) = tmp13 - tmp16; 98 | c_re(inout[iostride]) = tmp13 + tmp16; 99 | c_im(inout[0]) = tmp17 + tmp18; 100 | tmp19 = K866025403 * (tmp6 - tmp11); 101 | tmp20 = tmp18 - (K500000000 * tmp17); 102 | c_im(inout[iostride]) = tmp19 + tmp20; 103 | c_im(inout[2 * iostride]) = tmp20 - tmp19; 104 | } 105 | } 106 | } 107 | 108 | static const int twiddle_order[] = 109 | {1, 2}; 110 | fftw_codelet_desc fftwi_twiddle_3_desc = 111 | { 112 | "fftwi_twiddle_3", 113 | (void (*)()) fftwi_twiddle_3, 114 | 3, 115 | FFTW_BACKWARD, 116 | FFTW_TWIDDLE, 117 | 77, 118 | 2, 119 | twiddle_order, 120 | }; 121 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/fftw/generic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | /* 21 | * 22 | * generic.c -- "generic" codelets. They work for all n (and they are 23 | * slow) 24 | */ 25 | #include "fftw-int.h" 26 | #include 27 | 28 | void fftw_twiddle_generic(fftw_complex *A, const fftw_complex *W, 29 | int m, int r, int n, int stride) 30 | { 31 | int i, j, k; 32 | const fftw_complex *jp; 33 | fftw_complex *kp; 34 | fftw_complex *tmp = (fftw_complex *) 35 | fftw_malloc(r * sizeof(fftw_complex)); 36 | 37 | for (i = 0; i < m; ++i) { 38 | for (k = 0, kp = tmp; k < r; ++k, kp++) { 39 | fftw_real r0, i0, rt, it, rw, iw; 40 | int l1 = i + m * k; 41 | int l0; 42 | 43 | r0 = i0 = 0.0; 44 | for (j = 0, jp = A + i * stride, l0 = 0; j < r; ++j, 45 | jp += m * stride) { 46 | rw = c_re(W[l0]); 47 | iw = c_im(W[l0]); 48 | rt = c_re(*jp); 49 | it = c_im(*jp); 50 | r0 += rt * rw - it * iw; 51 | i0 += rt * iw + it * rw; 52 | l0 += l1; 53 | if (l0 >= n) 54 | l0 -= n; 55 | } 56 | c_re(*kp) = r0; 57 | c_im(*kp) = i0; 58 | } 59 | for (k = 0, kp = A + i * stride; k < r; ++k, kp += m * stride) 60 | *kp = tmp[k]; 61 | } 62 | 63 | fftw_free(tmp); 64 | } 65 | 66 | void fftwi_twiddle_generic(fftw_complex *A, const fftw_complex *W, 67 | int m, int r, int n, int stride) 68 | { 69 | int i, j, k; 70 | const fftw_complex *jp; 71 | fftw_complex *kp; 72 | fftw_complex *tmp = (fftw_complex *) 73 | fftw_malloc(r * sizeof(fftw_complex)); 74 | 75 | for (i = 0; i < m; ++i) { 76 | for (k = 0, kp = tmp; k < r; ++k, kp++) { 77 | fftw_real r0, i0, rt, it, rw, iw; 78 | int l1 = i + m * k; 79 | int l0; 80 | 81 | r0 = i0 = 0.0; 82 | for (j = 0, jp = A + i * stride, l0 = 0; j < r; ++j, 83 | jp += m * stride) { 84 | rw = c_re(W[l0]); 85 | iw = c_im(W[l0]); 86 | rt = c_re(*jp); 87 | it = c_im(*jp); 88 | r0 += rt * rw + it * iw; 89 | i0 += it * rw - rt * iw; 90 | l0 += l1; 91 | if (l0 >= n) 92 | l0 -= n; 93 | } 94 | c_re(*kp) = r0; 95 | c_im(*kp) = i0; 96 | } 97 | for (k = 0, kp = A + i * stride; k < r; ++k, kp += m * stride) 98 | *kp = tmp[k]; 99 | } 100 | 101 | fftw_free(tmp); 102 | } 103 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/fftw/rfftw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | /* rfftw.h -- system-wide definitions for rfftw */ 21 | #ifndef RFFTW_H 22 | #define RFFTW_H 23 | 24 | #include "fftw.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | /****************************************************************************/ 31 | 32 | #define RFFTW_V2 33 | 34 | typedef fftw_plan rfftw_plan; 35 | typedef fftwnd_plan rfftwnd_plan; 36 | 37 | #define FFTW_REAL_TO_COMPLEX FFTW_FORWARD 38 | #define FFTW_COMPLEX_TO_REAL FFTW_BACKWARD 39 | 40 | extern void rfftw(rfftw_plan plan, int howmany, fftw_real *in, int istride, 41 | int idist, fftw_real *out, int ostride, int odist); 42 | extern void rfftw_one(rfftw_plan plan, fftw_real *in, fftw_real *out); 43 | 44 | extern rfftw_plan rfftw_create_plan_specific(int n, fftw_direction dir, 45 | int flags, 46 | fftw_real *in, int istride, 47 | fftw_real *out, int ostride); 48 | 49 | extern rfftw_plan rfftw_create_plan(int n, fftw_direction dir, int flags); 50 | extern void rfftw_destroy_plan(rfftw_plan plan); 51 | 52 | extern void rfftw_fprint_plan(FILE *f, rfftw_plan p); 53 | extern void rfftw_print_plan(rfftw_plan p); 54 | 55 | extern void rfftw_executor_simple(int n, fftw_real *in, 56 | fftw_real *out, 57 | fftw_plan_node *p, 58 | int istride, 59 | int ostride, 60 | fftw_recurse_kind recurse_kind); 61 | 62 | extern rfftwnd_plan rfftwnd_create_plan_specific(int rank, const int *n, 63 | fftw_direction dir, int flags, 64 | fftw_real *in, int istride, 65 | fftw_real *out, int ostride); 66 | extern rfftwnd_plan rfftw2d_create_plan_specific(int nx, int ny, 67 | fftw_direction dir, int flags, 68 | fftw_real *in, int istride, 69 | fftw_real *out, int ostride); 70 | extern rfftwnd_plan rfftw3d_create_plan_specific(int nx, int ny, int nz, 71 | fftw_direction dir, int flags, 72 | fftw_real *in, int istride, 73 | fftw_real *out, int ostride); 74 | extern rfftwnd_plan rfftwnd_create_plan(int rank, const int *n, 75 | fftw_direction dir, int flags); 76 | extern rfftwnd_plan rfftw2d_create_plan(int nx, int ny, 77 | fftw_direction dir, int flags); 78 | extern rfftwnd_plan rfftw3d_create_plan(int nx, int ny, int nz, 79 | fftw_direction dir, int flags); 80 | extern void rfftwnd_destroy_plan(rfftwnd_plan plan); 81 | extern void rfftwnd_fprint_plan(FILE *f, rfftwnd_plan plan); 82 | extern void rfftwnd_print_plan(rfftwnd_plan plan); 83 | extern void rfftwnd_real_to_complex(rfftwnd_plan p, int howmany, 84 | fftw_real *in, int istride, int idist, 85 | fftw_complex *out, int ostride, int odist); 86 | extern void rfftwnd_complex_to_real(rfftwnd_plan p, int howmany, 87 | fftw_complex *in, int istride, int idist, 88 | fftw_real *out, int ostride, int odist); 89 | extern void rfftwnd_one_real_to_complex(rfftwnd_plan p, 90 | fftw_real *in, fftw_complex *out); 91 | extern void rfftwnd_one_complex_to_real(rfftwnd_plan p, 92 | fftw_complex *in, fftw_real *out); 93 | 94 | /****************************************************************************/ 95 | 96 | #ifdef __cplusplus 97 | } /* extern "C" */ 98 | #endif /* __cplusplus */ 99 | #endif /* RFFTW_H */ 100 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/fftw/wisdomio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997-1999 Massachusetts Institute of Technology 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "fftw-int.h" 24 | 25 | /**************** import/export using file ***************/ 26 | 27 | static void file_emitter(char c, void *data) 28 | { 29 | putc(c, (FILE *) data); 30 | } 31 | 32 | void fftw_export_wisdom_to_file(FILE *output_file) 33 | { 34 | if (output_file) 35 | fftw_export_wisdom(file_emitter, (void *) output_file); 36 | } 37 | 38 | static int file_get_input(void *data) 39 | { 40 | return getc((FILE *) data); 41 | } 42 | 43 | fftw_status fftw_import_wisdom_from_file(FILE *input_file) 44 | { 45 | if (!input_file) 46 | return FFTW_FAILURE; 47 | return fftw_import_wisdom(file_get_input, (void *) input_file); 48 | } 49 | 50 | /*************** import/export using string **************/ 51 | 52 | static void emission_counter(char c, void *data) 53 | { 54 | int *counter = (int *) data; 55 | 56 | ++*counter; 57 | } 58 | 59 | static void string_emitter(char c, void *data) 60 | { 61 | char **output_string = (char **) data; 62 | 63 | *((*output_string)++) = c; 64 | **output_string = 0; 65 | } 66 | 67 | char *fftw_export_wisdom_to_string(void) 68 | { 69 | int string_length = 0; 70 | char *s, *s2; 71 | 72 | fftw_export_wisdom(emission_counter, (void *) &string_length); 73 | 74 | s = (char *) fftw_malloc(sizeof(char) * (string_length + 1)); 75 | if (!s) 76 | return 0; 77 | s2 = s; 78 | 79 | fftw_export_wisdom(string_emitter, (void *) &s2); 80 | 81 | if (s + string_length != s2) 82 | fftw_die("Unexpected output string length!\n"); 83 | 84 | return s; 85 | } 86 | 87 | static int string_get_input(void *data) 88 | { 89 | char **input_string = (char **) data; 90 | 91 | if (**input_string) 92 | return *((*input_string)++); 93 | else 94 | return 0; 95 | } 96 | 97 | fftw_status fftw_import_wisdom_from_string(const char *input_string) 98 | { 99 | const char *s = input_string; 100 | 101 | if (!input_string) 102 | return FFTW_FAILURE; 103 | return fftw_import_wisdom(string_get_input, (void *) &s); 104 | } 105 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/glut32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/viewFeatrueExtract/3DAlignmentCode/glut32.dll -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/3DAlignmentCode/thin.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned char DelTab[256] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1}; 3 | unsigned char IsDel(unsigned char *flag, int coor, int *MaskCoor) 4 | { 5 | int k, index; 6 | 7 | index = 0; 8 | for(k=1; k<9; k++) 9 | index += flag[coor+MaskCoor[k]] << (k-1); 10 | 11 | return DelTab[index]; 12 | } 13 | 14 | int DelSide(unsigned char *flag, unsigned char *src, unsigned char *SilhMask, int width, int TotalSize, int *MaskCoor, int side) 15 | { 16 | int j, k; 17 | int change; 18 | 19 | change = 0; 20 | 21 | // left-right, top-bottom 22 | for(j=width; j=0 60 | for(i=0; i 5 | #include 6 | #include 7 | 8 | typedef uint8_t BYTE; 9 | 10 | 11 | struct POINT { 12 | int x, y; 13 | }; 14 | 15 | #endif // end of __WIN_TYPES_H__ 16 | 17 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/extractFeatrue/extractFeature: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaoguangcheng/DeepNet/8f8543e2e141d7f878195c32ddf66af5c08c4e83/multi_modality/viewFeatrueExtract/extractFeatrue/extractFeature -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/extractFeatrue/extractFeature.cpp: -------------------------------------------------------------------------------- 1 | #include "extractFeature.h" 2 | #include "parameter.h" 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | void help() 9 | { 10 | cout << "======================================================="<< endl; 11 | cout << "[usage] : extractFeature depthImagePath nVoacabulary prefixOfSaveBOW knn llcMethod lambda" << endl; 12 | cout << "=======================================================" << endl; 13 | } 14 | 15 | int main(int argc,char* argv[]) 16 | { 17 | 18 | if(argc < 4){ 19 | help(); 20 | return -1; 21 | } 22 | 23 | uint64 start = getTickCount(); 24 | 25 | parameter::imageFilePath = string(argv[1]); 26 | parameter::nVocabulary = atoi(argv[2]); 27 | parameter::pathToSaveBOW = string(argv[3]); 28 | 29 | if(argc >= 5) 30 | parameter::knn = atoi(argv[4]); 31 | if(argc >= 6) 32 | parameter::method = parameter::LLCMethod(atoi(argv[5])); 33 | if(argc >= 7) 34 | parameter::lambda =atof(argv[6]); 35 | 36 | parameter p; 37 | p.saveParameters(); 38 | p.print(); 39 | 40 | vector siftDescriptorForAll,siftDescriptorAfterMerge; 41 | extractSiftDescriptor(parameter::imageFilePath,siftDescriptorForAll); 42 | mergeModelSiftDescriptor(siftDescriptorForAll,siftDescriptorAfterMerge); 43 | 44 | vector bow; 45 | computeBOW(siftDescriptorAfterMerge,parameter::nVocabulary,bow, parameter::pathToSaveBOW, true); 46 | // computeLLCBOW(siftDescriptorAfterMerge,parameter::nVocabulary,bow, parameter::pathToSaveBOW, true); 47 | 48 | // vector tf_idf; 49 | // calTF_IDF(bow,tf_idf,parameter::pathToSaveBOW); 50 | 51 | // vector zca; 52 | // cal_ZCA(bow,zca,parameter::pathToSaveBOW,true); 53 | 54 | uint64 finish = getTickCount(); 55 | 56 | cout << "===================================" << endl; 57 | cout << "depth images path : " << parameter::imageFilePath << endl; 58 | cout << "total models : " << bow.size() << endl; 59 | cout << "number of vocabulary : " << parameter::nVocabulary << endl; 60 | cout << "time consumed : " << (finish-start)/getTickFrequency() << endl; 61 | cout << "===================================" << endl; 62 | 63 | return 0; 64 | 65 | // Mat m; 66 | // m.create(3000,128,5); 67 | // loadMat(string(argv[1]), m); 68 | // cout << m << endl; 69 | } 70 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/extractFeatrue/extractFeature.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (2.01a) Tue Oct 8 17:11:31 2013 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = 7 | DEPENDPATH += . fftw 8 | INCLUDEPATH += . fftw 9 | 10 | # Input 11 | HEADERS += \ 12 | extractFeature.h \ 13 | parameter.h 14 | SOURCES += \ 15 | extractFeature.cpp 16 | 17 | OPENCV_TOP = /opt/opencv-2.4.5 18 | INCLUDEPATH += \ 19 | $$OPENCV_TOP/include/opencv $$OPENCV_TOP/include \ 20 | /opt/ffmpeg-1.0/include /user/include/qt4/QtGui 21 | 22 | LIBS += \ 23 | -L$$OPENCV_TOP/lib \ 24 | -lopencv_calib3d -lopencv_contrib -lopencv_core \ 25 | -lopencv_features2d -lopencv_flann \ 26 | -lopencv_highgui -lopencv_imgproc -lopencv_legacy \ 27 | -lopencv_ml -lopencv_nonfree -lopencv_objdetect \ 28 | -lopencv_photo -lopencv_stitching -lopencv_ts \ 29 | -lopencv_video -lopencv_videostab \ 30 | -L/opt/ffmpeg-1.0/lib \ 31 | -lavcodec -lswscale -lavutil \ 32 | -lSDL -lz -lpthread 33 | 34 | INCLUDEPATH += /opt/eigen3/include/eigen3 35 | LIBS += -L/opt/eigen3 -leigen_blas 36 | 37 | -------------------------------------------------------------------------------- /multi_modality/viewFeatrueExtract/extractFeatrue/parameter.h: -------------------------------------------------------------------------------- 1 | #ifndef PARAMETER_H 2 | #define PARAMETER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | class parameter 11 | { 12 | public: 13 | enum LLCMethod{defaultMethod = 0,SUM,MAX}; 14 | 15 | //declaration 16 | static double lambda; 17 | static int knn; 18 | static LLCMethod method; 19 | static string imageFilePath; 20 | static int nVocabulary; 21 | static string pathToSaveBOW; 22 | 23 | void print() 24 | { 25 | cout << "lambda : " << lambda << endl; 26 | cout << "knn : " << knn << endl; 27 | cout << "LLCMethod : " << method<< endl; 28 | cout << "imageFilePath : " << imageFilePath << endl; 29 | cout << "nVocabulary : " << nVocabulary << endl; 30 | cout << "pathToSaveBOW : " << pathToSaveBOW << endl; 31 | cout << endl; 32 | } 33 | 34 | void saveParameters() 35 | { 36 | FILE *fp; 37 | if((fp = fopen("parameters--record.txt","a+")) == NULL){ 38 | printf("can not open file : %s\n","parameters--record.txt"); 39 | return; 40 | } 41 | 42 | time_t tmVal; 43 | struct tm *tmPtr; 44 | char buf[256]; 45 | 46 | time(&tmVal); 47 | tmPtr = localtime(&tmVal); 48 | sprintf(buf,"%d:%d:%d, %d-%d-%d",tmPtr->tm_hour,tmPtr->tm_min, 49 | tmPtr->tm_sec,tmPtr->tm_year+1900,tmPtr->tm_mon+1,tmPtr->tm_mday); 50 | 51 | fprintf(fp,"---%s---\n",buf); 52 | fprintf(fp,"imageFilePath : %s\n",imageFilePath.c_str()); 53 | fprintf(fp,"nVocabulary : %d\n",nVocabulary); 54 | fprintf(fp,"pathToSaveBOW : %s\n",pathToSaveBOW.c_str()); 55 | fprintf(fp,"method : %d\n",method); 56 | fprintf(fp,"lambda : %lf\n",lambda); 57 | fprintf(fp,"knn : %d\n",knn); 58 | fprintf(fp,"\n"); 59 | 60 | fclose(fp); 61 | } 62 | }; 63 | 64 | //default parameters(definition and initialization) 65 | parameter::LLCMethod parameter::method = parameter::defaultMethod; 66 | double parameter::lambda = 1e-4; 67 | int parameter::knn = 5; 68 | int parameter::nVocabulary = -1; 69 | string parameter::imageFilePath = ""; 70 | string parameter::pathToSaveBOW = ""; 71 | 72 | #endif // PARAMETER_H 73 | --------------------------------------------------------------------------------