source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Inference/OldVersion/LearnAlignBeta.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 6.8 KB
Line 
1% *  This code was used in the following articles:
2% *  [1] Learning 3-D Scene Structure from a Single Still Image,
3% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
4% *      In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
5% *      (best paper)
6% *  [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
7% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
8% *      In ICCV workshop on Virtual Representations and Modeling
9% *      of Large-scale environments (VRML), 2007.
10% *  [3] 3-D Depth Reconstruction from a Single Still Image,
11% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
12% *      International Journal of Computer Vision (IJCV), Aug 2007.
13% *  [6] Learning Depth from Single Monocular Images,
14% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
15% *      In Neural Information Processing Systems (NIPS) 18, 2005.
16% *
17% *  These articles are available at:
18% *  http://make3d.stanford.edu/publications
19% *
20% *  We request that you cite the papers [1], [3] and [6] in any of
21% *  your reports that uses this code.
22% *  Further, if you use the code in image3dstiching/ (multiple image version),
23% *  then please cite [2].
24% * 
25% *  If you use the code in third_party/, then PLEASE CITE and follow the
26% *  LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
27% *
28% *  Finally, this code is for non-commercial use only.  For further
29% *  information and to obtain a copy of the license, see
30% *
31% *  http://make3d.stanford.edu/publications/code
32% *
33% *  Also, the software distributed under the License is distributed on an
34% * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
35% *  express or implied.   See the License for the specific language governing
36% *  permissions and limitations under the License.
37% *
38% */
39function [] =LearnAlignBeta(WeiBatchNumber,LearnOrTest);
40
41FeaflagFull = 1
42
43if nargin < 22
44        LearnOrTest = 0;
45end
46thresh = 90000;
47
48
49% This funciton Learn Beta for the Alignment term
50
51global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory...
52       ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default...
53       Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize PopUpVertY PopUpHoriX taskName;
54NuPics = size(filename,2);
55NuRow = NuRow_default;% 55
56batchRow = 1:WeiBatchSize:NuRow;%[1 6 .... 51]
57Window = ceil(VertYNuDepth*0.05);
58
59%PicsInd = 1:2:NuPics; % learn only on half of the image
60PicsInd = 1:NuPics; % learn only on half of the image
61%PicsInd = [10:16 54:62];
62%PicsInd = [62];
63batchRow(WeiBatchNumber):min(batchRow(WeiBatchNumber)+WeiBatchSize-1,NuRow)
64for j = batchRow(WeiBatchNumber):min(batchRow(WeiBatchNumber)+WeiBatchSize-1,NuRow)
65%for j = 1:NuRow
66  for l = 1:2
67   Target = [];
68   Feature = [];
69    tic;
70    for i = PicsInd%1:10%1:NuPics
71%        i
72%        load([ScratchDataFolder '/data/SupFea/FeaNList' num2str(i) '.mat']); % load nList (y3 x4 )and FeaNList
73        load([ScratchDataFolder '/data/SupFea/FeaNList' num2str(i) 'new.mat']); % load nList (y3 x4 )and FeaNList
74        PickMaskY = ceil(nList(:,3)*VertYNuDepth) <= j+Window & ceil(nList(:,3)*VertYNuDepth) > j-Window;
75        if l == 1;
76           PickMaskOri = abs(nList(:,5:6)*[1 0]') > abs(nList(:,5:6)*[0 1]');% hori
77        else
78           PickMaskOri = abs(nList(:,5:6)*[1 0]') <= abs(nList(:,5:6)*[0 1]');% vert
79        end
80        PickMask = PickMaskY & PickMaskOri;
81        if FeaflagFull
82           disp('full fea')
83           Feature = [Feature; FeaNList(PickMask,:)];
84%        disp('[1:204 613:end]')
85        else
86           Feature = [Feature; FeaNList(PickMask,[1:204 613:end])]; %use only abs diff features and neighbors
87        end
88%        Feature = [Feature; FeaNList(PickMask,1:204)]; %use only abs diff features
89%        size(Feature)
90        [OccluList]=LaserOccluLabel(i,nList(:,1:2));
91%        size(OccluList(PickMask))
92        Target = [Target; OccluList(PickMask)];
93    end
94    TrainOccluPrecent = sum(Target==1)/size(Target,1)
95    NuTarget = size(Target,1)
96
97    clear FeaNList nList;
98    pack;
99
100%    figure(300);
101%    plot(Target);
102
103    if LearnOrTest == 0
104        % start learning
105        disp('Starting training...........');
106        size([Target ones(size(Target))])
107        if size([Target ones(size(Target))],1) > thresh
108           disp('Target too big');
109           pick = randperm(thresh);
110           Target = Target(pick,:);
111           Feature = Feature(pick,:);
112           size([Target ones(size(Target))])
113        end
114        Psi = glmfit(Feature, [Target ones(size(Target))], 'binomial', 'link', 'logit');
115        disp('.......Finished Training');
116    else
117%       load([ScratchDataFolder '/data/AlignLearn/AlignLearnHori_' num2str(j) '.mat'] );
118%       load([ScratchDataFolder '/data/AlignLearnNew/AlignLearnHori_' num2str(j) '.mat'] );
119%       load([ScratchDataFolder '/data/AlignLearnAbsDiff/AlignLearnHori_' num2str(j) '.mat'] );
120        load([ScratchDataFolder '/data/AlignLearnAbsDiffNei/AlignLearnHori_' num2str(j) '.mat'] );
121    end
122       
123    softPredictedTarget = glmval(Psi, Feature, 'logit');
124    predictedTarget = softPredictedTarget > 0.5;
125
126    PositiveAccuracy = sum( (Target == predictedTarget) .* (Target == 1) ) / ...
127                                                sum(  (Target == 1) )
128    NegativeAccuracy = sum( (Target == predictedTarget) .* (Target == 0) ) / ...
129                                                sum(  (Target == 0) )
130    if l ==1
131%       save([ScratchDataFolder '/data/AlignLearn/AlignLearnHori_' num2str(j) '.mat'],...
132%            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent');
133      if FeaflagFull
134       save([ScratchDataFolder '/data/AlignLearnNew/AlignLearnHori_' num2str(j) '.mat'],...
135            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent','NuTarget');
136%       save([ScratchDataFolder '/data/AlignLearnAbsDiff/AlignLearnHori_' num2str(j) '.mat'],...
137%            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent','NuTarget');
138      else
139       save([ScratchDataFolder '/data/AlignLearnAbsDiffNei/AlignLearnHori_' num2str(j) '.mat'],...
140            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent','NuTarget');
141      end
142    else
143%       save([ScratchDataFolder '/data/AlignLearn/AlignLearnVert_' num2str(j) '.mat'],...
144%            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent');
145      if FeaflagFull
146       save([ScratchDataFolder '/data/AlignLearnNew/AlignLearnVert_' num2str(j) '.mat'],...
147            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent','NuTarget');
148      else
149%       save([ScratchDataFolder '/data/AlignLearnAbsDiff/AlignLearnVert_' num2str(j) '.mat'],...
150%            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent','NuTarget');
151       save([ScratchDataFolder '/data/AlignLearnAbsDiffNei/AlignLearnVert_' num2str(j) '.mat'],...
152            'Psi','PositiveAccuracy','NegativeAccuracy','TrainOccluPrecent','NuTarget');
153      end
154    end
155    toc
156    clear Target Feature Psi;
157  end
158end
Note: See TracBrowser for help on using the repository browser.