| start: |
(1) | import numpy, sklearn, tensorflow, keras as np1, sk, tf, kr |
(2) | def convert_img_array(img): |
| If img not None: |
| Return array of img |
| else |
| Return np1.array[] |
(3) | for I in imgdir://…imgdir contains list of images |
| imgList[].append(convert_img_array(img)) |
| labelList[].append(i.label)//…i.label gives label or class of each images |
(4) | modify labelList with label_binarizer library |
(5) | image_list = np1.array(imgList, dtype = np.float16)/225.0 |
(6) | train_test_split(image_list, labelList, 0.2,3) |
(7) | do Augmentation with Keras.ImageDataGenerator() |
(8) | Implement Models: |
| from keras.applications.vgg16 import VGG16 |
| from keras.applications.mobilenet import MobileNet |
(9) | models[].append(VGG16() & MobileNet) |
(10) | for i in range models: |
| Models[i].fit_transform();//to train the models |
(11) | Now combine prediction values; |
| For i in range models: |
| Yhat = models[i].prediction(); //stacked data set |
(12) | Now create stacked model |
| stackedx = call process 11 |
| Model = LogisticRegression(); |
13Now to train the stacked model: |
| Model.fit(stackedx, test_x); |
(14) | Now store prediction value of stacked model: |
| Yhat = Model.predict(stackedx) |
(15) | Now calculate accuracy: |
| Sklearn.accuracy_score(yhat, test_y) |
| end; |