Using cnn models trained on different datasets
I think it depends on the data.
You may use three different models and make three binary predictions on each image. So you get a vote (probability) for each x vs. normal. If binary classifications are accurate, this should deliver okay results. But you kind of get a cummulated missclassification or error in this case.
If you can afford, you can train a four class model and compare the test error to the series of binary classifications. I understand that you already have three models. So training another one may be not too expensive.
If ONLY one of the classes can occur, a four class model might be the way to go. If in fact two (or more) classes can occur jointly, a series of binary classifications would make sense.
Merge two different deep learning models in Keras
Sequential models are not suited for creating models with branches.
You can have the two independent models as Sequential models, as you did, but from the Concatenate
on, you should start using the functional Model API.
The idea is to get the output tensors of the two models and feed them in other layers to get new output tensors.
So, considering you have model
and extra
:
mergedOutput = Concatenate()([model.output, extra.output])
This mergetOutput
is a tensor. You can either create the last part of the model using this tensor, or create the last part independently, and call it on this tensor. The second approach may be good if you want to train each model separately (doesn't seem to be your case).
Now, creating the new model as a functional API model:
out = Dense(128, activation='relu')(mergetOutput)
out = Dropout(0.8)(out)
out = Dense(32, activation='sigmoid')(out)
out = Dense(num_classes, activation='softmax')(out)
new_model = Model(
[model.input, extra.input], #model with two input tensors
out #and one output tensor
)
An easier approach is to take all three models you have already created and use them to create a combined model:
model = Sequential() #your first model
extra = Sequential() #your second model
new_model = Sequential() #all these three exactly as you did
#in this case, you just need to add an input shape to new_model, compatible with the concatenated output of the previous models.
new_model.add(FirstNewModelLayer(...,input_shape=(someValue,)))
Join them like this:
mergedOutput = Concatenate()([model.output, extra.output])
finalOutput = new_model(mergedOutput)
fullModel = Model([model.input,extra.input],finalOutput)
Related Topics
How to Merge Elements in List in Python With Condition
How to Create Multiple Data Frames Using a for Loop in Python
Robot Framework Using Python, Key Press Without Selecting Any Button or Element in the Page
How to Convert Signed to Unsigned Integer in Python
Modulenotfounderror: What Does It Mean _Main_ Is Not a Package
Suppress Stdout/Stderr Print from Python Functions
Python Serial: How to Use the Read or Readline Function to Read More Than 1 Character At a Time
Python:Compare Two CSV Files and Print Out Differences
Import Local Module in Jupyter Notebook
What Else Do I Need for Codehs 8.3.8: Word Ladder
Compare a Column Between 2 CSV Files and Write Differences Using Python
How to Locate Elements on Webpage With Headless Chrome
How to Connect to a Remote Windows Machine to Execute Commands Using Python
Python Replace Single Quotes Except Apostrophes
Python: Pickle.Load() Raising Eoferror
Python: Printing Horizontally Rather Than Current Default Printing