@@ -96,40 +96,48 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
9696
9797 # println(typeof(numImgs));println(typeof(numFeatures))
9898 # create an empty array (of zeroes) with dimensions (numImgs, numFeautures)
99- global votes = zeros((numImgs, numFeatures)) # necessarily different from `zero.((numImgs, numFeatures))`
99+ global votes = zeros((numImgs, numFeatures)) # necessarily different from `zero.((numImgs, numFeatures))`; previously zerosarray
100100
101101 # bar = progressbar.ProgressBar()
102102 # @everywhere numImgs begin
103+ # println(size(votes))
103104 # println(votes)
104-
105+ # displaymatrix(votes)
106+ # println(length(features))
107+ # displaymatrix(features)
105108 # show progress bar
109+ # displaymatrix(images)
110+ # println(size(images))
106111 @everywhere begin
107112 n = numImgs
108- processes = length(numImgs) # i.e., hypotheses
109- p = Progress(n, 1) # minimum update interval: 1 second
110- for t in 1:processes # bar(range(num_imgs)):
113+ processes = numImgs # i.e., hypotheses
114+ # println(processes)
115+ # p = Progress(n, 1) # minimum update interval: 1 second
116+ @showprogress for t in 1:processes # bar(range(num_imgs)):
117+ # println(t)
111118 # votes[i, :] = np.array(list(Pool(processes=None).map(partial(_get_feature_vote, image=images[i]), features)))
112- # votes[i , :] = Array(map(partial(getVote , images[i ]), features))
113- votes[t, :] = Array(map(feature -> getVote(feature , images[t]), features))
119+ # votes[t , :] = Array(map(partial(_get_feature_vote , images[t ]), features))
120+ votes[t, :] = Array(map(f -> _get_feature_vote(f , images[t]), features))
114121 # votes[i, :] = [map(feature -> getVote(feature, images[i]), features)]
115- next!(p)
122+ # next!(p)
116123 end
117124 end # end everywhere (end parallel processing)
125+ # displaymatrix(votes)
118126
119127 # select classifiers
120128 # classifiers = Array()
121129 classifiers = []
122130
123- println("Selecting classifiers...")
131+ println("\nSelecting classifiers...")
124132
125133 n = numClassifiers
126- p = Progress(n, 1) # minimum update interval: 1 second
127- for t in 1:numClassifiers
134+ # p = Progress(n, 1) # minimum update interval: 1 second
135+ @showprogress for t in 1:numClassifiers
128136 # for t in processes
129137 # println(typeof(length(featureIndices)))
130138 # print_matrix(stdout, weights)
131139 # println(weights)
132- classificationErrors = zeros(length(featureIndices))
140+ classificationErrors = zeros(length(featureIndices)) # previously, zerosarray
133141
134142 # normalize the weights $w_{t,i}\gets \frac{w_{t,i}}{\sum_{j=1}^n w_{t,j}}$
135143 # weights *= 1. / np.sum(weights)
@@ -164,6 +172,7 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
164172
165173 classificationErrors[j] = ε
166174 end
175+ # print_matrix(stdout, weights)
167176
168177 # choose the classifier $h_t$ with the lowest error $\varepsilon_t$
169178 minErrorIDX = argmin(classificationErrors) # returns the index of the minimum in the array
@@ -179,7 +188,9 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
179188 # featureWeight = (1 - bestError) / bestError # β
180189 # println(typeof(featureWeight))
181190 # [println(f.weight) for f in features]
191+ # print_matrix(stdout, weights)
182192 bestFeature.weight = featureWeight
193+ # print_matrix(stdout, weights)
183194
184195 # classifiers = vcat(classifiers, bestFeature)
185196 # println(classifiers)
@@ -188,8 +199,22 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
188199 # update image weights $w_{t+1,i}=w_{t,i}\beta_{t}^{1-e_i}$
189200 # weights = list(map(lambda img_idx: weights[img_idx] * np.sqrt((1-best_error)/best_error) if labels[img_idx] != votes[img_idx, best_feature_idx] else weights[img_idx] * np.sqrt(best_error/(1-best_error)), range(num_imgs)))
190201 # weights = (imgIDX -> (labels[imgIDX] ≠ votes[imgIDX, bestFeatureIDX]) ? weights[imgIDX]*sqrt((1-bestError)/bestError) : weights[imgIDX]*sqrt(bestError/(1-bestError)), 1:numImgs)
202+ # print_matrix(stdout, weights)
203+ # weights = Array(map(imgIDX -> labels[imgIDX] ≠ votes[imgIDX, bestFeatureIDX] ? weights[imgIDX] * sqrt((1 - bestError) / bestError) : weights[imgIDX] * sqrt(bestError / (1 - bestError)), 1:numImgs))
204+ weights = Array(map(i -> labels[i] ≠ votes[i, bestFeatureIDX] ? weights[i] * sqrt((1 - bestError) / bestError) : weights[i] * sqrt(bestError / (1 - bestError)), 1:numImgs))
205+ # println(votes[:,bestFeatureIDX])
206+
207+ # print_matrix(stdout, weights)
208+ # println(typeof(weights))
191209
192- weights = Array(map(imgIDX -> (labels[imgIDX] ≠ votes[imgIDX, bestFeatureIDX]) ? weights[imgIDX] * featureWeight : weights[imgIDX] * featureWeight, 1:numImgs))
210+ # imgIDX -> labels[imgIDX] ≠ votes[imgIDX, bestFeatureIDX] ? weights[imgIDX] * sqrt((1 - bestError) / bestError) : weights[imgIDX] * sqrt(bestError / (1 - bestError))
211+
212+ # weights = np.array(list(map(
213+ #
214+ # lambda img_idx:
215+ # weights[img_idx] * np.sqrt((1-best_error)/best_error) if labels[img_idx] != votes[img_idx, best_feature_idx] else weights[img_idx] * np.sqrt(best_error/(1-best_error)),
216+ #
217+ # range(num_imgs))))
193218
194219 # β = ε / (1 - ε)
195220 #
@@ -207,15 +232,22 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
207232 featureIndices = filter! (e -> e ∉ bestFeatureIDX, featureIndices) # note: without unicode operators, `e ∉ [a, b]` is `!(e in [a, b])`
208233 # println(bestFeature)
209234
210- next! (p)
235+ # next!(p)
211236 end
237+ # println(weights)
212238
213239 # println(typeof(classifiers[1]))
240+ # println(votes)
214241 return classifiers
215242
216243end
217244
218245
246+ function _get_feature_vote(feature::HaarLikeFeature, image::AbstractArray)
247+ return getVote(feature, image)
248+ end
249+
250+
219251# function _get_feature_vote(feature::HaarLikeFeature, image::Int64)
220252# # return getVote(image)
221253# # return partial(getVote)(image)
0 commit comments