Can I train a CNN model with Two Image dataset at the same time

Viewed 199

I want to train a CNN model with two Image dataset at the same time.

Dataset1(RGB-Images[size(64,64,3)]) ->class-1:Fire Class-2:Non_Fire Dataset2(gray_scale-image[size(120,120,1)])->class-1:Fire Class-2:Non_Fire

Model output:Fire(class) or Non_Fire(class)

My dataset link: Dataset-1:

test_path1='/content/drive/MyDrive/Thesis_Dataset/Devide_Cnn/gt/test'
train_path1='/content/drive/MyDrive/Thesis_Dataset/Devide_Cnn/gt/train'
valid_path1='/content/drive/MyDrive/Thesis_Dataset/Devide_Cnn/gt/valid'

Dataset-2:

test_path2='/content/drive/MyDrive/Thesis_Dataset/Devide_Cnn/rgb/test'
train_path2='/content/drive/MyDrive/Thesis_Dataset/Devide_Cnn/rgb/train'
valid_path2='/content/drive/MyDrive/Thesis_Dataset/Devide_Cnn/rgb/valid'

I have found samle code from stackoverflow where used two dataset are Non Image data so that i cant understand how can i apply this code for my own problem .

**Can anyone help me how can i run fit operation on my two datasets using following sample code?????????? *Also can you please someone tell me whether this approach be helpful for accuracy or not??

Sample code from stackoverflow:(show me how can i run fit operarion for my two given image dataset)

from keras.layers import Conv2D, MaxPooling2D, Input, Dense, Flatten, concatenate
from keras.models import Model
import numpy as np

img_input = Input(shape=(64, 64, 1))  ## branch 1 with image input
x = Conv2D(64, (3, 3))(img_input)
x = Conv2D(64, (3, 3))(x)
x = MaxPooling2D((2, 2))(x)
x = Flatten()(x)
out_a = Dense(64)(x)

num_input = Input(shape=(7,))        ## branch 2 with numerical input
x1 = Dense(8, activation='relu')(num_input)
out_b = Dense(16, activation='relu')(x1)

concatenated = concatenate([out_a, out_b])    ## concatenate the two branches
out = Dense(4, activation='softmax')(concatenated)
model = Model([img_input, num_input], out)
print(model.summary())
model.compile('sgd', 'categorical_crossentropy', ['accuracy'])

### Just for sanity check
X = [np.zeros((1,64,64,1)), np.zeros((1,7))]
y = np.ones((1,4))
model.fit(X, y)
print(model.predict(X))
1 Answers

I think you can use pandas data frame, import both Dataset1 and Dataset2 into single data frame and then pass it to the network, if both the data sets having exactly similar data then you can directly merge both data sets. for accuracy you must improve the quality of data first and then work on neural network.

Related