Giter VIP home page Giter VIP logo

dedhiaparth98 / face-recognition Goto Github PK

View Code? Open in Web Editor NEW
27.0 27.0 19.0 2.92 MB

Face Recognition Model trained with Siamese Network and Triplet Loss function in TensorFlow

Home Page: https://towardsdatascience.com/building-face-recognition-model-under-30-minutes-2d1b0ef72fda

Python 0.10% Jupyter Notebook 99.73% CSS 0.05% HTML 0.13%
deep-learning face-recognition siamese-network siamese-neural-network tensorflow2 vgg16

face-recognition's Introduction

Hi there ๐Ÿ‘‹

I am currently implementing various Deep Learning and Computer Vision algorithms. I also enjoy learning python and implementing various libraries that makes development fast and fun.

About me: I like reading novels, painting, playing keyboard, and trekking

You could always reach me at ๐Ÿ“ซ LinkedIn

face-recognition's People

Contributors

dedhiaparth98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

face-recognition's Issues

Provided pretrained VGG16 weights

Hey, excellent blog! Really well explained and written. I was trying to train a model myself as a side learning project, I am not able train the VGG16 model that you trained according to the paper link, but the link does not lead anywhere. Would you be kind enough to provide me the pretrianed weights that I can use to do transfer learning?

ValueError: Failed to find data adapter that can handle input: <class '__main__.DataGenerator'>, <class 'NoneType'>

hello, Parth Dedhia. Thanks for making the blog and this repo.

i'm working on my thesis, i need the Triplet Generator so that i come across to your blog and this repo, but i got some issues. can you help me, please?

My own custom function

def align_image(img):
    return alignment.align(96, img, alignment.getLargestFaceBoundingBox(img), 
                           landmarkIndices=AlignDlib.OUTER_EYES_AND_NOSE)

DataGenerator Class

class DataGenerator(tf.keras.utils.Sequence):
    def __init__(self, dataset_path, batch_size=32, shuffle=True):
        self.dataset = self.__curate_dataset(dataset_path)
        self.dataset_path = dataset_path
        self.shuffle = shuffle
        self.batch_size = batch_size
        self.no_of_people = len(list(self.dataset.keys()))
        self.on_epoch_end()
        
    def __getitem__(self, index):
        people = list(self.dataset.keys())[index * self.batch_size: (index + 1) * self.batch_size]
        P = []
        A = []
        N = []
        
        for person in people:
            anchor_index = random.randint(0, len(self.dataset[person])-1)
            a = self.__get_image(person, anchor_index)
            
            positive_index = random.randint(0, len(self.dataset[person])-1)
            while positive_index == anchor_index:
                positive_index = random.randint(0, len(self.dataset[person])-1)
            p = self.__get_image(person, positive_index)
            
            negative_person_index = random.randint(0, self.no_of_people - 1)
            negative_person = list(self.dataset.keys())[negative_person_index]
            while negative_person == person:
                negative_person_index = random.randint(0, self.no_of_people - 1)
                negative_person = list(self.dataset.keys())[negative_person_index]
            
            negative_index = random.randint(0, len(self.dataset[negative_person])-1)
            n = self.__get_image(negative_person, negative_index)
            P.append(p)
            A.append(a)
            N.append(n)
        A = np.asarray(A)
        N = np.asarray(N)
        P = np.asarray(P)
        return [A, P, N]
        
    def __len__(self):
        return self.no_of_people // self.batch_size
        
    def __curate_dataset(self, dataset_path):
        with open(os.path.join(dataset_path, 'list.txt'), 'r') as f:
            dataset = {}
            image_list = f.read().splitlines()
            for image in image_list:
                folder_name, file_name = image.split('/')
                if folder_name in dataset.keys():
                    dataset[folder_name].append(file_name)
                else:
                    dataset[folder_name] = [file_name]
        return dataset
    
    def on_epoch_end(self):
        if self.shuffle:
            keys = list(self.dataset.keys())
            random.shuffle(keys)
            dataset_ =  {}
            for key in keys:
                dataset_[key] = self.dataset[key]
            self.dataset = dataset_
            
    def __get_image(self, person, index):
        img = cv2.imread(os.path.join(self.dataset_path, os.path.join('images/' + person, self.dataset[person][index])))
        img = align_image(img) #my own custom function
        img = np.asarray(img, dtype=np.float64)
        img = preprocess_input(img)
        return img
data_generator = DataGenerator(dataset_path='./dataset/')

when i was passing the data_generator to model.fit_generator().

nn4_small2_train.compile(loss=None, optimizer='adam')
nn4_small2_train.fit_generator(data_generator, epochs=5, steps_per_epoch=20)

i got this error
ValueError: Failed to find data adapter that can handle input: <class '__main__.DataGenerator'>, <class 'NoneType'>

i don't want to loop the data generator like the way you did. i want to pass through the model.fit_generator() immediately

why is the output <class 'NoneType'>?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.