forked from s18k/Active-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
644 lines (590 loc) · 24.9 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
import base64
import shutil
import io
import modAL
from flask import Flask, render_template, request
import pickle
import numpy as np
from io import StringIO
from flask import Flask, send_file
import numpy as np
import numpy
from setuptools import extension
from skimage.io import imsave
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from io import BytesIO
from PIL import Image
import os
from data import Data
import patoolib
import re
#import matplotlib
app = Flask(__name__)
app.secret_key = "super secret key"
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
UPLOAD_FOLD = 'D:/VIIT/FinalYear/Persistent_Project/Project_Data'
UPLOAD_FOLDER = os.path.join(APP_ROOT, UPLOAD_FOLD)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
import zipfile
from flask import Flask, request, redirect, url_for, flash, render_template
from werkzeug.utils import secure_filename
ALLOWED_EXTENSIONS = set(['zip','rar','png','jpeg','jpg'])
import numpy as np
from modAL.models import ActiveLearner
from modAL.uncertainty import uncertainty_sampling,entropy_sampling
from modAL.disagreement import vote_entropy_sampling,max_disagreement_sampling,max_std_sampling,consensus_entropy_sampling
from modAL.models import ActiveLearner, Committee
from modAL.models import BayesianOptimizer
from modAL.batch import uncertainty_batch_sampling
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from functools import partial
import numpy as np
# Set our RNG seed for reproducibility.
RANDOM_STATE_SEED = 1
np.random.seed(RANDOM_STATE_SEED)
from IPython import display
# from matplotlib import pyplot as plt
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
def random_sampling(classifier, X_pool):
n_samples = len(X_pool)
query_idx = np.random.choice(range(n_samples))
return query_idx, X_pool[query_idx]
# @app.route('/next')
def generate_image():
"""
Return a generated image as a png by
saving it into a StringIO and using send_file.
"""
num_tiles = 20
tile_size = 30
arr = np.random.randint(0, 255, (num_tiles, num_tiles, 3))
arr = arr.repeat(tile_size, axis=0).repeat(tile_size, axis=1)
# We make sure to use the PIL plugin here because not all skimage.io plugins
# support writing to a file object.
strIO = StringIO()
buffer = BytesIO()
imsave(buffer, arr, plugin='pil', format_str='png')
buffer.seek(0)
return send_file(buffer, mimetype='image/png')
@app.route("/predict")
def predict():
return render_template("predict.html")
@app.route("/result",methods=['GET','POST'])
def result():
data = Data.getData()
learner = data.learner
committee = data.committee
classlist = data.classlist
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
filename = secure_filename(file.filename)
option = 0
if file and allowed_file(file.filename):
if(filename.split(".")[1]=="rar"):
option = 1
patoolib.extract_archive(os.path.join(UPLOAD_FOLDER, filename), outdir=os.path.join(UPLOAD_FOLDER))
elif(filename.split(".")[1]=="zip"):
option = 1
zip_ref = zipfile.ZipFile(os.path.join(UPLOAD_FOLDER, filename), 'r')
zip_ref.extractall(UPLOAD_FOLDER)
zip_ref.close()
print("Succesfull")
else:
filename = secure_filename(file.filename)
file.save(os.path.join(UPLOAD_FOLDER, filename))
image = Image.open(os.path.join(UPLOAD_FOLDER, filename))
image = image.resize((200,200), Image.ANTIALIAS)
size = np.array(image).size
x = numpy.array(image).reshape((1,size))
if learner!=None:
label = learner.predict(x)
elif committee!=None:
label = committee.predict(x)
print(label)
print(classlist[label[0]]['name'])
return render_template("result.html",name=classlist[label[0]]['name'])
if(option==1):
list = []
for dirname, _, filenames in os.walk(os.path.join(UPLOAD_FOLDER,filename.split(".")[0])):
print(filenames)
for filename in filenames:
if('.jpg' in filename or 'jpeg' in filename or 'png' in filename):
image = Image.open(os.path.join(dirname, filename))
image = image.resize((200,200), Image.ANTIALIAS)
size = np.array(image).size
x = numpy.array(image).reshape((1,size))
try:
if learner!=None:
label = learner.predict(x)
elif committee!=None:
label = committee.predict(x)
list.append({"image":filename,"Label":classlist[label[0]]['name']})
except:
continue
print(list)
return render_template("result.html",list = list)
# print("!")
# list = []
#
# for imfile in os.listdir(os.path.join(UPLOAD_FOLDER,filename.split(".")[0])):
# print(imfile)
# if imfile.endswith(".jpg") or imfile.endswith(".jpeg") or imfile.endswith(".png"):
# image = Image.open(os.path.join(os.path.join(UPLOAD_FOLDER,filename.split(".")[0]), imfile))
# image = image.resize((200,200), Image.ANTIALIAS)
# size = np.array(image).size
# x = numpy.array(image).reshape((1,size))
# try:
# if learner!=None:
# label = learner.predict(x)
# elif committee!=None:
# label = committee.predict(x)
# list.append({"image":imfile,"Label":classlist[label[0]]['name']})
# except:
# continue
# print(list)
# return render_template("result.html",list = list)
else:
return render_template("result.html",name="Sorry")
# shutil.rmtree(os.path.join(app.config['UPLOAD_FOLDER'],filename.split(".")[0]))
# if file and allowed_file(file.filename):
# filename = secure_filename(file.filename)
# file.save(os.path.join(UPLOAD_FOLDER, filename))
# image = Image.open(os.path.join(UPLOAD_FOLDER, filename))
# image = image.resize((200,200), Image.ANTIALIAS)
# size = np.array(image).size
# x = numpy.array(image).reshape((1,size))
# if learner!=None:
# label = learner.predict(x)
# elif committee!=None:
# label = committee.predict(x)
# print(label)
# print(classlist[label[0]]['name'])
# return render_template("result.html",name=classlist[label[0]]['name'])
# else:
# return render_template("result.html",name="Sorry something went wrong")
@app.route("/")
def main():
return render_template("index.html",data=[{'name':'Random Forest'}, {'name':'KNN'}, {'name':'Decision Tree'}],
query=[{'name':'Uncertainty Sampling'},{'name':'Entropy Sampling'},
{'name':'Random Sampling'},
{'name':'Query By Committee(Uncertainty Sampling)'},
{'name':'Query By Committee(Vote Entropy Sampling)'},
{'name':'Query By Committee(Max Disagreement Sampling)'},
{'name':'Query By Committee(Max STD Sampling)'},
{'name':'Query By Committee(Consensus Entropy Sampling)'}
],
structure=[{'name':'Label Name given to Folder Containing Images','id':0},
{'name':'Label Name given to Images','id':1}
])
@app.route('/train', methods=['POST'])
def helper():
data = Data.getData()
queries = data.queries
X_test = data.X_test
y_test = data.y_test
X_pool = data.X_pool
y_pool = data.y_pool
counter = data.counter
learner = data.learner
committee = data.committee
accuracy = data.accuracy
classlist = data.classlist
print(classlist)
print(counter)
print(queries)
if(int(counter)==int(queries)):
if(learner != None):
query_idx, query_inst = learner.query(X_pool)
elif(committee!=None):
query_idx, query_inst = committee.query(X_pool)
try:
arr = query_inst.reshape(200,200,3)
except:
arr = query_inst.reshape(200,200)
rescaled = (255.0 / arr.max() * (arr - arr.min())).astype(np.uint8)
im = Image.fromarray(rescaled)
new_size = (300, 300)
im = im.resize(new_size)
filename = secure_filename("image.png")
# os.remove(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(filename)))
im.save(os.path.join(os.path.join(APP_ROOT, 'C:/Users/ASUS/PycharmProjects/Active Learning/static'), secure_filename(filename)))
# im_data = io.BytesIO()
# im.save(im_data, "JPEG")
# encoded_img_data = base64.b64encode(im_data.getvalue())
X_pool, y_pool = np.delete(X_pool, query_idx, axis=0), np.delete(y_pool, query_idx, axis=0)
params = {}
params["X_pool"] = X_pool
params["y_pool"] = y_pool
params["counter"] = int(counter)-1
if learner!=None:
params["accuracy"] = learner.score(X_test,y_test)
elif committee!=None:
params["accuracy"] = committee.score(X_test, y_test)
data.setdata(params)
print("Initial classlist ",classlist)
return render_template("after.html",classlist=classlist,UPLOAD_FOLDER=UPLOAD_FOLDER+"/image.png")
elif(int(counter)>=1):
if(learner != None):
query_idx, query_inst = learner.query(X_pool)
elif(committee!=None):
query_idx, query_inst = committee.query(X_pool)
try:
arr = query_inst.reshape(200,200,3)
except:
arr = query_inst.reshape(200,200)
rescaled = (255.0 / arr.max() * (arr - arr.min())).astype(np.uint8)
im = Image.fromarray(rescaled)
new_size = (300, 300)
im = im.resize(new_size)
filename = secure_filename("image.png")
# os.remove(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(filename)))
im.save(os.path.join(os.path.join(APP_ROOT, 'C:/Users/ASUS/PycharmProjects/Active Learning/static'), secure_filename(filename)))
# im_data = io.BytesIO()
# im.save(im_data, "JPEG")
# encoded_img_data = base64.b64encode(im_data.getvalue())
y_new = np.array([int(request.form.get('label_select'))],dtype=int)
if(learner!=None):
learner.teach(query_inst.reshape(1, -1), y_new)
elif(committee!=None):
committee.teach(query_inst.reshape(1, -1), y_new)
X_pool, y_pool = np.delete(X_pool, query_idx, axis=0), np.delete(y_pool, query_idx, axis=0)
params = {}
params["X_pool"] = X_pool
params["y_pool"] = y_pool
params["counter"] = int(counter)-1
if learner!=None:
params["accuracy"] = learner.score(X_test,y_test)
print(learner.score(X_test,y_test))
elif committee!=None:
params["accuracy"] = committee.score(X_test, y_test)
data.setdata(params)
accuracy_string = ""
count = 0
iterations = ""
for i in data.accuracy:
n = float(i)
n*=100
accuracy_string +=str(n)
accuracy_string +=","
iterations+=str(count)
iterations+=","
count+=1
accuracy_string = accuracy_string[:-1]
iterations = iterations[:-1]
print("Accuracy string",accuracy_string)
return render_template("after.html",data = accuracy_string,iteration = iterations,classlist=classlist,UPLOAD_FOLDER=UPLOAD_FOLDER+"\image.png")
else:
accuracy_string = ""
iterations = ""
count = 0
for i in data.accuracy:
n = float(i)
n *= 100
accuracy_string += str(n)
accuracy_string += ","
iterations += str(count)
iterations += ","
count += 1
accuracy_string = accuracy_string[:-1]
iterations = iterations[:-1]
print("Final",accuracy_string,iterations)
return render_template("final.html",accuracy = float(data.accuracy[-1])*100,data = accuracy_string,iteration = iterations,)
@app.route('/next',methods=['GET','POST'])
def query():
# n_initial = 100
# X, y = load_digits(return_X_y=True)
# X_train, X_test, y_train, y_test = train_test_split(X, y)
#
# initial_idx = np.random.choice(range(len(X_train)), size=n_initial, replace=False)
#
# X_initial, y_initial = X_train[initial_idx], y_train[initial_idx]
# X_pool, y_pool = np.delete(X_train, initial_idx, axis=0), np.delete(y_train, initial_idx, axis=0)
strategy = None
classifier = None
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
filename = secure_filename(file.filename)
# shutil.rmtree(os.path.join(app.config['UPLOAD_FOLDER'],filename.split(".")[0]))
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(UPLOAD_FOLDER, filename))
if(filename.split(".")[1]=="rar"):
patoolib.extract_archive(os.path.join(UPLOAD_FOLDER, filename), outdir=os.path.join(UPLOAD_FOLDER))
else:
zip_ref = zipfile.ZipFile(os.path.join(UPLOAD_FOLDER, filename), 'r')
zip_ref.extractall(UPLOAD_FOLDER)
zip_ref.close()
print("Succesfull")
st = request.form.get('strategy_select')
cl = request.form.get('classifier_select')
option = int(request.form.get('structure_select'))
print(cl)
if(str(cl)=='Random Forest'):
classifier = RandomForestClassifier()
elif(str(cl)=='KNN'):
classifier = KNeighborsClassifier()
else:
classifier = DecisionTreeClassifier()
n_queries = request.form['queries']
print(st)
classlist =[]
classes = {}
data = {}
data['image'] = []
data['label'] = []
filename = secure_filename(file.filename)
print(filename)
if option == 0:
for dirname, _, filenames in os.walk(os.path.join(UPLOAD_FOLDER,filename.split(".")[0])):
print(filenames)
for filename in filenames:
if('.jpg' in filename or 'jpeg' in filename or 'png' in filename):
image = Image.open(os.path.join(dirname, filename))
image = image.resize((200,200), Image.ANTIALIAS)
size = np.array(image).size
if(len(classes)==0):
data['image'] = np.array(numpy.array(image)).reshape((1,size))
else:
try:
x = numpy.array(image).reshape((1,size))
data['image'] = np.append(data['image'],x,axis=0)
except:
continue
if(dirname.split('\\')[-1] not in classes.keys()):
classlist.append({'name':dirname.split('\\')[-1],'number':len(classes)})
classes[dirname.split('\\')[-1]] = len(classes)
#print(os.path.join(dirname, filename))
#print(dirname)
data['label'].append(classes[dirname.split('\\')[-1]])
print(classes)
else:
for imfile in os.listdir(os.path.join(UPLOAD_FOLDER,filename.split(".")[0])):
if imfile.endswith(".jpg") or imfile.endswith(".jpeg") or imfile.endswith("png"):
image = Image.open(os.path.join(os.path.join(UPLOAD_FOLDER,filename.split(".")[0]), imfile))
image = image.resize((200,200), Image.ANTIALIAS)
size = np.array(image).size
if(len(classes)==0):
data['image'] = np.array(numpy.array(image)).reshape((1,size))
else:
try:
x = numpy.array(image).reshape((1,size))
data['image'] = np.append(data['image'],x,axis=0)
except:
continue
if(("".join(re.split("[^a-zA-Z]*",imfile.split(".")[0]))) not in classes.keys()):
classlist.append({'name':("".join(re.split("[^a-zA-Z]*",imfile.split(".")[0]))),'number':len(classes)})
classes[("".join(re.split("[^a-zA-Z]*",imfile.split(".")[0])))] = len(classes)
data['label'].append(classes[("".join(re.split("[^a-zA-Z]*",imfile.split(".")[0])))])
print(classes)
else:
continue
X = data['image']
y = data['label']
n_initial = 100
X_train, X_test, y_train, y_test = train_test_split(X, y)
initial_idx = np.random.choice(range(len(X_train)), size=n_initial, replace=False)
X_initial=[]
y_initial = []
print(type(X_initial))
for i in range(n_initial):
v = np.array(X_train[initial_idx[i]]).reshape((1,size))
#print(v.shape)
y_initial.append(y_train[i])
if(i==0):
X_initial = np.array(X_train[initial_idx[i]]).reshape((1,size))
print(X_initial.shape)
else:
X_initial = np.append(X_initial,v,axis=0)
#print("X Shape",X_initial.shape)
# X_initial = X_initial.append(X_train[initial_idx[i]])
X_pool, y_pool = np.delete(X_train, initial_idx, axis=0), np.delete(y_train, initial_idx, axis=0)
print(X.shape)
print(X[0].shape)
print(X_initial.shape)
params = {}
params["X_test"] = X_test
params["y_test"] = y_test
params["counter"] = n_queries
params["X_pool"] = X_pool
params["y_pool"] = y_pool
if(str(st)=='Uncertainty Sampling'):
print(classifier)
print(cl)
learner = ActiveLearner(
estimator=classifier,
query_strategy=uncertainty_sampling,
X_training=X_initial, y_training=y_initial
)
params["learner"] = learner
accuracy_scores = learner.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,learner,None,accuracy,X_test,y_test,classlist,n_queries)
print("Calling Helper")
return helper()
elif(str(st)=='Entropy Sampling'):
print(classifier)
print(cl)
learner = ActiveLearner(
estimator=classifier,
query_strategy=entropy_sampling,
X_training=X_initial, y_training=y_initial
)
params["learner"] = learner
accuracy_scores = learner.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,learner,None,accuracy,X_test,y_test,classlist,n_queries)
return helper()
elif(str(st)=='Random Sampling'):
learner = ActiveLearner(
estimator=classifier,
query_strategy=random_sampling,
X_training=X_train, y_training=y_train
)
accuracy_scores = learner.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,learner,None,accuracy,X_test,y_test,classlist,n_queries)
return helper()
elif(str(st)=='Query By Committee(Vote Entropy Sampling)'):
learner1 = ActiveLearner(
estimator = RandomForestClassifier(),
X_training=X_train,y_training=y_train
)
learner2 = ActiveLearner(
estimator=KNeighborsClassifier(),
X_training=X_train,y_training=y_train
)
learner3 = ActiveLearner(
estimator=DecisionTreeClassifier(),
X_training=X_train,y_training=y_train
)
committee = Committee(
learner_list=[learner1,learner2,learner3],
query_strategy=vote_entropy_sampling
)
params["committee"] = committee
accuracy_scores = committee.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,None,committee,accuracy,X_test,y_test,classlist,n_queries)
return helper()
elif(str(st)=='Query By Committee(Uncertainty Sampling)'):
learner1 = ActiveLearner(
estimator = RandomForestClassifier(),
X_training=X_train,y_training=y_train
)
learner2 = ActiveLearner(
estimator=KNeighborsClassifier(),
X_training=X_train,y_training=y_train
)
learner3 = ActiveLearner(
estimator=DecisionTreeClassifier(),
X_training=X_train,y_training=y_train
)
committee = Committee(
learner_list=[learner1,learner2,learner3],
query_strategy=uncertainty_sampling
)
params["committee"] = committee
accuracy_scores = committee.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,None,committee,accuracy,X_test,y_test,classlist,n_queries)
return helper()
elif(str(st)=='Query By Committee(Max Disagreement Sampling)'):
learner1 = ActiveLearner(
estimator = RandomForestClassifier(),
X_training=X_train,y_training=y_train
)
learner2 = ActiveLearner(
estimator=KNeighborsClassifier(),
X_training=X_train,y_training=y_train
)
learner3 = ActiveLearner(
estimator=DecisionTreeClassifier(),
X_training=X_train,y_training=y_train
)
committee = Committee(
learner_list=[learner1,learner2,learner3],
query_strategy=max_disagreement_sampling
)
params["committee"] = committee
accuracy_scores = committee.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,None,committee,accuracy,X_test,y_test,classlist,n_queries)
return helper()
elif(str(st)=='Query By Committee(Max STD Sampling)'):
learner1 = ActiveLearner(
estimator = RandomForestClassifier(),
X_training=X_train,y_training=y_train
)
learner2 = ActiveLearner(
estimator=KNeighborsClassifier(),
X_training=X_train,y_training=y_train
)
learner3 = ActiveLearner(
estimator=DecisionTreeClassifier(),
X_training=X_train,y_training=y_train
)
committee = Committee(
learner_list=[learner1,learner2,learner3],
query_strategy=max_std_sampling
)
params["committee"] = committee
accuracy_scores = committee.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,None,committee,accuracy,X_test,y_test,classlist,n_queries)
return helper()
elif(str(st)=='Query By Committee(Consensus Entropy Sampling)'):
learner1 = ActiveLearner(
estimator = RandomForestClassifier(),
X_training=X_train,y_training=y_train
)
learner2 = ActiveLearner(
estimator=KNeighborsClassifier(),
X_training=X_train,y_training=y_train
)
learner3 = ActiveLearner(
estimator=DecisionTreeClassifier(),
X_training=X_train,y_training=y_train
)
committee = Committee(
learner_list=[learner1,learner2,learner3],
query_strategy=consensus_entropy_sampling
)
params["committee"] = committee
accuracy_scores = committee.score(X_test, y_test)
params["accuracy"] = accuracy_scores
print(accuracy_scores)
accuracy = []
accuracy.append(accuracy_scores)
data = Data(n_queries,X_pool,y_pool,None,committee,accuracy,X_test,y_test,classlist,n_queries)
return helper()
app.run(debug=True)