@@ -96,40 +96,48 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
96
96
97
97
# println(typeof(numImgs));println(typeof(numFeatures))
98
98
# 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
100
100
101
101
# bar = progressbar.ProgressBar()
102
102
# @everywhere numImgs begin
103
+ # println(size(votes))
103
104
# println(votes)
104
-
105
+ # displaymatrix(votes)
106
+ # println(length(features))
107
+ # displaymatrix(features)
105
108
# show progress bar
109
+ # displaymatrix(images)
110
+ # println(size(images))
106
111
@everywhere begin
107
112
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)
111
118
# 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))
114
121
# votes[i, :] = [map(feature -> getVote(feature, images[i]), features)]
115
- next!(p)
122
+ # next!(p)
116
123
end
117
124
end # end everywhere (end parallel processing)
125
+ # displaymatrix(votes)
118
126
119
127
# select classifiers
120
128
# classifiers = Array()
121
129
classifiers = []
122
130
123
- println("Selecting classifiers...")
131
+ println("\nSelecting classifiers...")
124
132
125
133
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
128
136
# for t in processes
129
137
# println(typeof(length(featureIndices)))
130
138
# print_matrix(stdout, weights)
131
139
# println(weights)
132
- classificationErrors = zeros(length(featureIndices))
140
+ classificationErrors = zeros(length(featureIndices)) # previously, zerosarray
133
141
134
142
# normalize the weights $w_{t,i}\gets \frac{w_{t,i}}{\sum_{j=1}^n w_{t,j}}$
135
143
# weights *= 1. / np.sum(weights)
@@ -164,6 +172,7 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
164
172
165
173
classificationErrors[j] = ε
166
174
end
175
+ # print_matrix(stdout, weights)
167
176
168
177
# choose the classifier $h_t$ with the lowest error $\varepsilon_t$
169
178
minErrorIDX = argmin(classificationErrors) # returns the index of the minimum in the array
@@ -179,7 +188,9 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
179
188
# featureWeight = (1 - bestError) / bestError # β
180
189
# println(typeof(featureWeight))
181
190
# [println(f.weight) for f in features]
191
+ # print_matrix(stdout, weights)
182
192
bestFeature.weight = featureWeight
193
+ # print_matrix(stdout, weights)
183
194
184
195
# classifiers = vcat(classifiers, bestFeature)
185
196
# println(classifiers)
@@ -188,8 +199,22 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
188
199
# update image weights $w_{t+1,i}=w_{t,i}\beta_{t}^{1-e_i}$
189
200
# 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)))
190
201
# 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))
191
209
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))))
193
218
194
219
# β = ε / (1 - ε)
195
220
#
@@ -207,15 +232,22 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
207
232
featureIndices = filter! (e -> e ∉ bestFeatureIDX, featureIndices) # note: without unicode operators, `e ∉ [a, b]` is `!(e in [a, b])`
208
233
# println(bestFeature)
209
234
210
- next! (p)
235
+ # next!(p)
211
236
end
237
+ # println(weights)
212
238
213
239
# println(typeof(classifiers[1]))
240
+ # println(votes)
214
241
return classifiers
215
242
216
243
end
217
244
218
245
246
+ function _get_feature_vote(feature::HaarLikeFeature, image::AbstractArray)
247
+ return getVote(feature, image)
248
+ end
249
+
250
+
219
251
# function _get_feature_vote(feature::HaarLikeFeature, image::Int64)
220
252
# # return getVote(image)
221
253
# # return partial(getVote)(image)
0 commit comments