Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting false logo detection #3

Open
mahima97 opened this issue Dec 3, 2019 · 5 comments
Open

Getting false logo detection #3

mahima97 opened this issue Dec 3, 2019 · 5 comments

Comments

@mahima97
Copy link

mahima97 commented Dec 3, 2019

I trained the model architecture and got good result on train and val dataset. But when I give an unknown brand logo query and its target image its detects the logo but when I give other brands query image keeping target image same even then it detects the logo. E.g I gave bata logo query image and then bata target image it detects the bata logo but when I changed the query image to samsung it still detects bata logo in target image . Where as Ideally it should give blank mask.Please help. I am stuck.

@AyanKumarBhunia
Copy link
Owner

There might be some problems in your training process. You may share the code, I can give a quick checking.

@mahima97
Copy link
Author

mahima97 commented Dec 9, 2019

``
import keras
from keras.layers import Input
from keras.models import Model
import tensorflow as tf
from keras.layers import Activation,Lambda
from keras import optimizers
from keras.callbacks import ModelCheckpoint
import numpy as np
import cv2
import argparse
from keras.models import load_model
import keras.backend as K
from keras.callbacks import Callback
import os
from model import create_model
import data

class EpochCheckpoint(Callback):
def init(self, outputPath, every=5, startAt=0):
# call the parent constructor
super(Callback, self).init()
# store the base output path for the model, the number of
# epochs that must pass before the model is serialized to
# disk and the current epoch value
self.outputPath = outputPath
self.every = every
self.intEpoch = startAt
def on_epoch_end(self, epoch, logs={}):
if (self.intEpoch + 1) % self.every == 0:
p = os.path.sep.join([self.outputPath,
"epoch_{}.h5".format(self.intEpoch + 1)])
self.model.save(p, overwrite=True)
self.intEpoch += 1
ap = argparse.ArgumentParser()
ap.add_argument("-m", "--model", type=str,
help="path to specific model checkpoint to load")
ap.add_argument("-s", "--start-epoch", type=int, default=0,
help="epoch to restart training at")
args = vars(ap.parse_args())

batch_size = 8
Input1=Input(shape=[256, 256, 3])
Input2=Input(shape=[64, 64, 3])
output = create_model(Input1,Input2)

model = Model(inputs=[Input1, Input2], outputs=output)

if args["model"] is None:
print("[INFO] compiling model...")
model.summary()
sgd = optimizers.SGD(lr=0.0001, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(optimizer=sgd,loss='binary_crossentropy',
metrics=['accuracy'])
else:
print("[INFO] loading {}...".format(args["model"]))
sgd = optimizers.SGD(lr=0.0001, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(optimizer=sgd,loss='binary_crossentropy',
metrics=['accuracy'])
model.load_weights(args["model"])

batch_size = 8
train_data,test_data = data.load_data()

print(len(train_data),len(test_data))

def image_generator(files,batch_size = 8):
while True:
num = batch_size
idx = np.arange(0 , len(files))
np.random.shuffle(idx)
idx = idx[:num]
Input1_shuffle = []
Input2_shuffle = []

    out_shuffle = []

    for i in idx:
        Input1_shuffle += [cv2.resize(cv2.imread(files[i][0]),(256,256))/255.]
        Input2_shuffle += [cv2.resize(cv2.imread(files[i][1]),(64,64))/255.]
        out_shuffle += [(cv2.resize(cv2.imread(files[i][2],0),(256,256))/255.).reshape((256,256,1))]
    batch_x1 = np.array( Input1_shuffle )
    batch_x2 = np.array( Input2_shuffle )
    batch_y = np.array( out_shuffle )

    yield( [batch_x1,batch_x2], batch_y )

n = len(train_data)
n2 = len(test_data)

checkpoint = EpochCheckpoint('backups/', every=1,startAt=args["start_epoch"])
callbacks_list = [checkpoint]
model.fit_generator(image_generator(train_data,batch_size = batch_size),
validation_data=image_generator(test_data,batch_size = batch_size)
,validation_steps= n2 // batch_size,steps_per_epoch=n // batch_size,
epochs=10,callbacks=[checkpoint],verbose=1)

model.save("model.h5")
``

@AyanKumarBhunia
Copy link
Owner

Can you show some generated examples from your code that you are talking about?

@mahima97
Copy link
Author

wierd_output

@henuliulei
Copy link

could you share your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants