Train a custom object to Tensorflow Object Detection Model

Previous Article – https://wp.me/p6xoZs-3y

To do this there are few steps to follow, there are,

  1. Collect a few hundred images that contain your object – The bare minimum would be about 100, ideally more like 500+, but, the more images you have, the more tedious step 2 is…
  2. Annotate/label the images, ideally with a program. I personally used LabelImg. This process is basically drawing boxes around your object(s) in an image. The label program automatically will create an XML file that describes the object(s) in the pictures.
  3. Split this data into train/test samples
  4. Generate TF Records from these splits
  5. Setup a .config file for the model of choice (you could train your own from scratch, but we’ll be using transfer learning)
  6. Train
  7. Export graph from new trained model
  8. Detect custom objects in real time!

Next Article – https://wp.me/p6xoZs-3G

Spring Single Session Login

When you want to configure your application for single session login, that’s mean user can login to application only from one session. Normally even in google, they allow to login to the system from different browsers or devices; but if you want to limit this to a single browser/device/session; this is the way.

At the first time I was looking this solution from different sources, but couldn’t find. Finally I got this solution from a friend of mine and it works perfectly. This is how I did it.

Please follow below steps,

Step 01 – Update Security Configuration

You have to set below configuration to the spring security configuration.


.sessionManagement()
.invalidSessionUrl("/login")
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
.expiredUrl("/login")

Note : In above configuration we set the no of session to one and allow to prevent login when maximum no of session reached.

Then you have to add below bean as well.


@Bean
public HttpSessionEventPublisher httpSessionEventPublisher() {
    return new HttpSessionEventPublisher();
}

Note : You can write a custom HttpSessionEventPublisher if you want, here I used the existing one which spring gives default.

Step 02 – Update UserDetails Implemented Domain

Now you have to find the domain which UserDetails implemented. (When Application configured with spring security,  we have to create a object which implements the UserDetails object)

Add below methods at end of the Domain class.


@Override
public boolean equals(Object otherUser) {
   if (otherUser == null)
   return false;
   else if (!(otherUser instanceof UserDetails))
   return false;
   else
   return (otherUser.hashCode() == hashCode());
}

@Override
public int hashCode() {
    StringBuffer sb = new StringBuffer();
    sb.append(this.emailAddress != null ? this.emailAddress : "");
    sb.append(this.userName != null ? this.userName : "");

    String hashCode = sb.toString();
    return hashCode.hashCode();
}

 

Add Copyright on Eclipse Automatically

In this way you can add the copyright to your newly created java files automatically in eclipse.

Go to preferences -> Java -> Code Style -> Code Templates, expands Code and select “New Java Files”, edit the template to add whatever copyright messages you want.

eclipse_copyright_isdjava

After you complete above step, you will see your newly created java classes as below,

package lk.pwc.ird.automation.exceltoxml;

/*
* Created By idewasuren001 - Nov 21, 2018
*/

public class Test{

}