{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-23T04:46:53.290531Z","iopub.execute_input":"2023-04-23T04:46:53.29121Z","iopub.status.idle":"2023-04-23T04:49:20.586288Z","shell.execute_reply.started":"2023-04-23T04:46:53.291179Z","shell.execute_reply":"2023-04-23T04:49:20.585135Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\ndf_train = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:41.038423Z","iopub.execute_input":"2023-04-23T04:50:41.039143Z","iopub.status.idle":"2023-04-23T04:50:41.162237Z","shell.execute_reply.started":"2023-04-23T04:50:41.039105Z","shell.execute_reply":"2023-04-23T04:50:41.1611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DF_train = df_train[df_train['biopsy'] == 1].reset_index(drop = True)\nDF_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:42.907308Z","iopub.execute_input":"2023-04-23T04:50:42.907953Z","iopub.status.idle":"2023-04-23T04:50:42.932759Z","shell.execute_reply.started":"2023-04-23T04:50:42.907913Z","shell.execute_reply":"2023-04-23T04:50:42.931715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RSNA_512_path = '/kaggle/input/rsna-breast-cancer-512-pngs'\nfor i in range(len(DF_train)):\n    DF_train.loc[i, 'path'] = os.path.join(RSNA_512_path + '/' + str(DF_train.loc[i, 'patient_id']) + '_' + str(DF_train.loc[i, 'image_id']) + '.png')\nDF_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:43.203936Z","iopub.execute_input":"2023-04-23T04:50:43.205305Z","iopub.status.idle":"2023-04-23T04:50:44.434255Z","shell.execute_reply.started":"2023-04-23T04:50:43.205263Z","shell.execute_reply":"2023-04-23T04:50:44.433149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\ntrain_df , val_df = train_test_split(DF_train,test_size=0.3,stratify=DF_train[['cancer']])\nprint('train:',train_df.shape,'validation:',val_df.shape)\nprint('train:',train_df['cancer'].value_counts())\nprint('validation:',val_df['cancer'].value_counts())","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:44.653257Z","iopub.execute_input":"2023-04-23T04:50:44.653986Z","iopub.status.idle":"2023-04-23T04:50:45.094308Z","shell.execute_reply.started":"2023-04-23T04:50:44.65395Z","shell.execute_reply":"2023-04-23T04:50:45.092969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_normal = train_df[train_df['cancer'] == 0].reset_index(drop = True)\ntrain_df_cancer = train_df[train_df['cancer'] == 1].reset_index(drop = True)\nval_df_normal = val_df[val_df['cancer'] == 0].reset_index(drop = True)\nval_df_cancer = val_df[val_df['cancer'] == 1].reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:46.277948Z","iopub.execute_input":"2023-04-23T04:50:46.278659Z","iopub.status.idle":"2023-04-23T04:50:46.288836Z","shell.execute_reply.started":"2023-04-23T04:50:46.278619Z","shell.execute_reply":"2023-04-23T04:50:46.287886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\n# Define the destination directory.\ndestination_dir = '/kaggle/working/train'\ndestination_dir_sub = '/kaggle/working/train/normal'\n\n# Create the destination directory if it doesn't exist.\nif not os.path.exists(destination_dir):\n    os.makedirs(destination_dir)\n\nif not os.path.exists(destination_dir_sub):\n    os.makedirs(destination_dir_sub)   \n    \n# Copy the images to the destination directory.\nfor path in train_df_normal['path']:\n    shutil.copy2(path, destination_dir_sub)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:47.761935Z","iopub.execute_input":"2023-04-23T04:50:47.763088Z","iopub.status.idle":"2023-04-23T04:50:57.160144Z","shell.execute_reply.started":"2023-04-23T04:50:47.76302Z","shell.execute_reply":"2023-04-23T04:50:57.159095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define the destination directory.\ndestination_dir = '/kaggle/working/train'\ndestination_dir_sub = '/kaggle/working/train/cancer'\n\n# Create the destination directory if it doesn't exist.\nif not os.path.exists(destination_dir):\n    os.makedirs(destination_dir)\n\nif not os.path.exists(destination_dir_sub):\n    os.makedirs(destination_dir_sub)   \n    \n# Copy the images to the destination directory.\nfor path in train_df_cancer['path']:\n    shutil.copy2(path, destination_dir_sub)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:50:57.163412Z","iopub.execute_input":"2023-04-23T04:50:57.164457Z","iopub.status.idle":"2023-04-23T04:51:03.277467Z","shell.execute_reply.started":"2023-04-23T04:50:57.164411Z","shell.execute_reply":"2023-04-23T04:51:03.276423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define the destination directory.\ndestination_dir = '/kaggle/working/val'\ndestination_dir_sub = '/kaggle/working/val/normal'\n\n# Create the destination directory if it doesn't exist.\nif not os.path.exists(destination_dir):\n    os.makedirs(destination_dir)\n\nif not os.path.exists(destination_dir_sub):\n    os.makedirs(destination_dir_sub)   \n    \n# Copy the images to the destination directory.\nfor path in val_df_normal['path']:\n    shutil.copy2(path, destination_dir_sub)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:51:03.2789Z","iopub.execute_input":"2023-04-23T04:51:03.279297Z","iopub.status.idle":"2023-04-23T04:51:07.183269Z","shell.execute_reply.started":"2023-04-23T04:51:03.279258Z","shell.execute_reply":"2023-04-23T04:51:07.182177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define the destination directory.\ndestination_dir = '/kaggle/working/val'\ndestination_dir_sub = '/kaggle/working/val/cancer'\n\n# Create the destination directory if it doesn't exist.\nif not os.path.exists(destination_dir):\n    os.makedirs(destination_dir)\n\nif not os.path.exists(destination_dir_sub):\n    os.makedirs(destination_dir_sub)   \n    \n# Copy the images to the destination directory.\nfor path in val_df_cancer['path']:\n    shutil.copy2(path, destination_dir_sub)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:51:17.066938Z","iopub.execute_input":"2023-04-23T04:51:17.067673Z","iopub.status.idle":"2023-04-23T04:51:19.608525Z","shell.execute_reply.started":"2023-04-23T04:51:17.067634Z","shell.execute_reply":"2023-04-23T04:51:19.607463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nnormal_train_images = glob.glob('/kaggle/working/train/normal/*.png')\ncancer_train_images = glob.glob('/kaggle/working/train/cancer/*.png')","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:51:21.69483Z","iopub.execute_input":"2023-04-23T04:51:21.695207Z","iopub.status.idle":"2023-04-23T04:51:21.708759Z","shell.execute_reply.started":"2023-04-23T04:51:21.695173Z","shell.execute_reply":"2023-04-23T04:51:21.707565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing.image import ImageDataGenerator\ntrain_generate = ImageDataGenerator(rescale = 1./255.,\n                          zoom_range = 0.2)\nval_generate = ImageDataGenerator(rescale = 1./255.)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:51:22.927954Z","iopub.execute_input":"2023-04-23T04:51:22.928657Z","iopub.status.idle":"2023-04-23T04:51:30.367702Z","shell.execute_reply.started":"2023-04-23T04:51:22.928619Z","shell.execute_reply":"2023-04-23T04:51:30.366476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = '/kaggle/working/train'\nval_path = '/kaggle/working/val'\n\ntrain_generator = train_generate.flow_from_directory(\n    train_path,\n    target_size = (512, 512),\n    batch_size = 32,\n    class_mode = 'binary'\n)\nvalidation_generator = val_generate.flow_from_directory(\n        val_path,\n        target_size = (512, 512),\n        batch_size = 16,\n        class_mode = 'binary'\n)","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:51:51.851527Z","iopub.execute_input":"2023-04-23T04:51:51.852937Z","iopub.status.idle":"2023-04-23T04:51:52.066198Z","shell.execute_reply.started":"2023-04-23T04:51:51.852888Z","shell.execute_reply":"2023-04-23T04:51:52.065232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications.resnet_v2 import ResNet50V2\nfrom tensorflow.keras.optimizers import RMSprop\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nfrom keras.applications.vgg16 import VGG16\nbase_model = ResNet50V2(weights = 'imagenet', input_shape = (512, 512, 3), include_top = False)\nintermediate_model = VGG16(weights='imagenet',include_top=False,\n                           input_shape=(16,16,2048))\n\nfor layer in base_model.layers:\n    layer.trainable = False\nfor layer in intermediate_model.layers:\n    layer.trainable=False\n    \nmodel = Sequential()\nmodel.add(base_model)\nmodel.add(intermediate_model)\nmodel.add(GlobalAveragePooling2D())\nmodel.add(Dense(128, activation = 'relu'))\nmodel.add(Dropout(0.2))\nmodel.add(Dense(1, activation = 'sigmoid'))\n\nmodel.compile(optimizer = \"adam\", loss = 'binary_crossentropy', metrics = [\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:52:59.392758Z","iopub.execute_input":"2023-04-23T04:52:59.393274Z","iopub.status.idle":"2023-04-23T04:53:04.831723Z","shell.execute_reply.started":"2023-04-23T04:52:59.393236Z","shell.execute_reply":"2023-04-23T04:53:04.830064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_Res = ResNet50V2(weights = 'imagenet', input_shape = (512, 512, 3), include_top = False)\nmodel_Res.trainable=False","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:53:06.437805Z","iopub.execute_input":"2023-04-23T04:53:06.438832Z","iopub.status.idle":"2023-04-23T04:53:07.983619Z","shell.execute_reply.started":"2023-04-23T04:53:06.438779Z","shell.execute_reply":"2023-04-23T04:53:07.982585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import concatenate,Input\nmodel_VGG = VGG16(weights='imagenet',include_top=False,input_shape=(512,512,3))\nmodel_VGG.trainable=False\n\nresnet_input = Input(shape=(224, 224, 3))\nvgg_input = Input(shape=(224, 224, 3))\n\n# Connect inputs to the models\nresnet_output = resnet_model(resnet_input)\nvgg_output = vgg_model(vgg_input)\n\nmerged_model = concatenate([model_Res.output, model_VGG.output])\nx = Dense(256, activation='relu')(merged_model)\nx = Dense(128, activation='relu')(x)\nx = Dense(64, activation='relu')(x)\noutput = Dense(2, activation='softmax')(x)\n\n# model2.compile(optimizer = \"adam\", loss = 'binary_crossentropy', metrics = [\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:43:46.992547Z","iopub.execute_input":"2023-04-22T19:43:46.993661Z","iopub.status.idle":"2023-04-22T19:43:47.449762Z","shell.execute_reply.started":"2023-04-22T19:43:46.993611Z","shell.execute_reply":"2023-04-22T19:43:47.447928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import StackingClassifier\nfrom sklearn.linear_model import LogisticRegression\nbase_classifiers = [('resnet', model1), ('vgg', model2)]\n\n# Create meta-classifier\nmeta_classifier = LogisticRegression()\n\n# Create stacking classifier\nstacking_classifier = StackingClassifier(estimators=base_classifiers, final_estimator=meta_classifier)","metadata":{"execution":{"iopub.status.busy":"2023-04-22T18:43:02.932096Z","iopub.execute_input":"2023-04-22T18:43:02.932536Z","iopub.status.idle":"2023-04-22T18:43:02.940287Z","shell.execute_reply.started":"2023-04-22T18:43:02.932494Z","shell.execute_reply":"2023-04-22T18:43:02.938998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# stacking_classifier.fit(train_generator)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(train_generator[0])\nfrom matplotlib import pyplot as plt\nx_train = []\nfor i in normal_train_images:\n    x_train.append((plt.imread(i),0))\n# plt.imread(normal_train_images)\n# x_train[0]\nfor i in cancer_train_images:\n    x_train.append((plt.imread(i),1))\n# np.random.shuffle(x_train)\nshuffled_data = np.random.permutation(x_train)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:13:44.56571Z","iopub.execute_input":"2023-04-22T19:13:44.566961Z","iopub.status.idle":"2023-04-22T19:13:55.135531Z","shell.execute_reply.started":"2023-04-22T19:13:44.566897Z","shell.execute_reply":"2023-04-22T19:13:55.134318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# x_train.find(shuffled_data[0])\nx_train_img = []\ny_train=[]\nfor i in shuffled_data:\n    x_train_img.append(i[0])\n    y_train.append(i[1])","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:17:22.806551Z","iopub.execute_input":"2023-04-22T19:17:22.80721Z","iopub.status.idle":"2023-04-22T19:17:22.814919Z","shell.execute_reply.started":"2023-04-22T19:17:22.807156Z","shell.execute_reply":"2023-04-22T19:17:22.813974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stacking_classifier.fit(x_train_img,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:17:47.407506Z","iopub.execute_input":"2023-04-22T19:17:47.408662Z","iopub.status.idle":"2023-04-22T19:17:47.442533Z","shell.execute_reply.started":"2023-04-22T19:17:47.408609Z","shell.execute_reply":"2023-04-22T19:17:47.440527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import Model\nensemble_model = Model(inputs=[model_Res.input, model_VGG.input], outputs=output)\n\n# Compile the ensemble model\nensemble_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n\n# Create an ImageDataGenerator for data preprocessing\n# datagen = ImageDataGenerator(rescale=1./255)\n\n# # Create data generators for training and validation data\n# train_generator = datagen.flow_from_directory(train_dir, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\n# val_generator = datagen.flow_from_directory(val_dir, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\n\n# Train the ensemble model\n\n\nensemble_model.fit(train_generator, epochs=15, validation_data=validation_generator)\n\n# Make predictions using the trained ensemble model\n# test_generator = datagen.flow_from_directory(test_dir, target_size=(224, 224), batch_size=batch_size, class_mode='categorical', shuffle=False)\n# predictions = ensemble_model.predict_generator(test_generator)","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:42:22.822282Z","iopub.execute_input":"2023-04-22T19:42:22.822733Z","iopub.status.idle":"2023-04-22T19:42:22.865548Z","shell.execute_reply.started":"2023-04-22T19:42:22.822689Z","shell.execute_reply":"2023-04-22T19:42:22.863761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imread(normal_train_images[0]).shape","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:40:20.802621Z","iopub.execute_input":"2023-04-22T19:40:20.803075Z","iopub.status.idle":"2023-04-22T19:40:20.814674Z","shell.execute_reply.started":"2023-04-22T19:40:20.803034Z","shell.execute_reply":"2023-04-22T19:40:20.813304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom keras.models import Sequential\nfrom keras.layers import Dense\nfrom keras.models import Model\nfrom keras.layers import concatenate, Input\nfrom keras.applications import resnet, vgg16\nfrom keras.preprocessing.image import ImageDataGenerator\nbatch_size=20\n\n# Create ResNet model\nresnet_model = resnet.ResNet50(include_top=False, weights='imagenet')\nresnet_model.trainable = False\n\n# Create VGGNet model\nvgg_model = vgg16.VGG16(include_top=False, weights='imagenet')\nvgg_model.trainable = False\n\n# Define input shapes for the models\nresnet_input = Input(shape=(224, 224, 3))\nvgg_input = Input(shape=(224, 224, 3))\n\n# Connect inputs to the models\nresnet_output = resnet_model(resnet_input)\nvgg_output = vgg_model(vgg_input)\n\n# Create ensemble model by concatenating the outputs of ResNet and VGGNet models\nmerged_model = concatenate([resnet_output, vgg_output])\nx = Dense(256, activation='relu')(merged_model)\nx = Dense(128, activation='relu')(x)\nx = Dense(64, activation='relu')(x)\noutput = Dense(2, activation='softmax')(x) # num_classes is the number of classes in the classification problem\n\n# Create the final ensemble model\nensemble_model = Model(inputs=[resnet_input, vgg_input], outputs=output)\n\n# Compile the ensemble model\nensemble_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n\n# Create an ImageDataGenerator for data preprocessing\ndatagen = ImageDataGenerator(rescale=1./255)\n\n# Create data generators for training and validation data\ntrain_generator = datagen.flow_from_directory(train_path, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\nval_generator = datagen.flow_from_directory(val_path, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\n\n# Train the ensemble model\nensemble_model.fit_generator(train_generator, epochs=15, validation_data=val_generator)\n\n# Make predictions using the trained ensemble model\ntest_generator = datagen.flow_from_directory(test_dir, target_size=(224, 224), batch_size=batch_size, class_mode='categorical', shuffle=False)\npredictions = ensemble_model.predict_generator(test_generator)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-22T19:47:23.362479Z","iopub.execute_input":"2023-04-22T19:47:23.363367Z","iopub.status.idle":"2023-04-22T19:47:26.980594Z","shell.execute_reply.started":"2023-04-22T19:47:23.363318Z","shell.execute_reply":"2023-04-22T19:47:26.978857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Flatten\nfrom keras.models import Model\nfrom keras.layers import concatenate, Input\nfrom keras.applications import resnet, vgg16\nfrom keras.preprocessing.image import ImageDataGenerator\nnum_classes=2\nbatch_size=20\nepochs=1\n# Create ResNet model\nresnet_model = resnet.ResNet50(include_top=False, weights='imagenet')\nresnet_model.trainable = False\n\n# Create VGGNet model\nvgg_model = vgg16.VGG16(include_top=False, weights='imagenet')\nvgg_model.trainable = False\n\n# Define input shapes for the models\nresnet_input = Input(shape=(224, 224, 3))\nvgg_input = Input(shape=(224, 224, 3))\n\n# Connect inputs to the models\nresnet_output = resnet_model(resnet_input)\nvgg_output = vgg_model(vgg_input)\n\nresnet_output = Flatten()(resnet_output)  # Flatten the output of ResNet model\nvgg_output = Flatten()(vgg_output) \n\n# Create ensemble model by concatenating the outputs of ResNet and VGGNet models\nmerged_model = concatenate([resnet_output, vgg_output])\nx = Dense(256, activation='relu')(merged_model)\nx = Dense(128, activation='relu')(x)\nx = Dense(64, activation='relu')(x)\noutput = Dense(num_classes, activation='softmax')(x) # num_classes is the number of classes in the classification problem\n\n# Create the final ensemble model\nensemble_model = Model(inputs=[resnet_input, vgg_input], outputs=output)\n\n# Compile the ensemble model\nensemble_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n\n# Create an ImageDataGenerator for data preprocessing\ndatagen = ImageDataGenerator(rescale=1./255)\n\n# Create data generators for training and validation data\ntrain_generator_resnet = datagen.flow_from_directory(train_path, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\ntrain_generator_vgg = datagen.flow_from_directory(train_path, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\nval_generator_resnet = datagen.flow_from_directory(val_path, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\nval_generator_vgg = datagen.flow_from_directory(val_path, target_size=(224, 224), batch_size=batch_size, class_mode='categorical')\n\n# Train the ensemble model\nfor epoch in range(epochs):\n    for (x_resnet, y_resnet), (x_vgg, y_vgg) in zip(train_generator_resnet, train_generator_vgg):\n        ensemble_model.fit([x_resnet, x_vgg], y_resnet, batch_size=batch_size)\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-04-23T04:58:40.798292Z","iopub.execute_input":"2023-04-23T04:58:40.79891Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Make predictions using the trained ensemble model\ntest_generator_resnet = datagen.flow_from_directory(test_dir, target_size=(224, 224), batch_size=batch_size, class_mode='categorical', shuffle=False)\ntest_generator_vgg = datagen.flow_from_directory(test_dir, target_size=(224, 224), batch_size=batch_size, class_mode='categorical', shuffle=False)\npredictions = ensemble_model.predict([test_generator_resnet, test_generator_vgg])","metadata":{},"execution_count":null,"outputs":[]}]}