We use Keras and Python 3 to learn and teach ML/AI/OpenCV concepts
# https://keras.io/ !pip install -q keras #if you are on Google Colab import keras import numpy as np from keras.models import Sequential from keras.layers import Activation, Flatten from keras.layers import Convolution2D from keras.utils import np_utils from keras.datasets import mnist # Load pre-shuffled MNIST data into train and test sets (X_train, y_train), (X_test, y_test) = mnist.load_data() print (X_train.shape) from matplotlib import pyplot as plt # %matplotlib inline plt.imshow(X_train) X_train = X_train.reshape(X_train.shape, 28, 28,1) X_test = X_test.reshape(X_test.shape, 28, 28,1) X_train = X_train.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_test /= 255 y_train[:10] # Convert 1-dimensional class arrays to 10-dimensional class matrices Y_train = np_utils.to_categorical(y_train, 10) Y_test = np_utils.to_categorical(y_test, 10) Y_train[:10] model = Sequential() model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(28,28,1))) model.add(Convolution2D(10, 1, activation='relu')) model.add(Convolution2D(10, 26)) model.add(Flatten()) model.add(Activation('softmax')) model.summary() model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) model.fit(X_train, Y_train, batch_size=32, nb_epoch=10, verbose=1) score = model.evaluate(X_test, Y_test, verbose=0) print(score) y_pred = model.predict(X_test) print(y_pred[:9]) print(y_test[:9])
Welcome to Machine Learning and AI - Bangalore Chapter.
We are a group of Machine Learning and Artificial Intelligence enthusiasts, learning and teaching ML/AI to all the group members.
Every week we conduct a hands-on session at our Stealth Labs. We meet to discuss concepts, algorithms, learning strategies, research papers and have featured talks by experts in industry and academia. The purpose is to build a learning community around students, researchers, corporations in Machine Learning and Artificial Intelligence.
This website is the home page for MLBLR where we will try and maintain all our content, code and meet-up session minutes.
Unlike other ML/AI focus groups, we also learn and teach OpenCV. We integrate OpenCV concepts, and leverage decades of experience in computer vision and augment our approach to AI/ML.
Remember, we meet nearly every week, so do not forget to check out our meetup calendar for more details.
Canny Edge Detector in OpenCV
import cv2 image = cv2.imread("ADD_LOCATION_OF_YOUR_IMAGE_HERE") edges = cv2.Canny(images, 10, 20) cv2.imwrite("ADD_LOCATION_WHERE_YOU_WANT_TO_SAVE_YOUR_IMAGE", edges)
From start, our focus is to get our hands dirty with code and concepts.
We would try and explain every concept through some code to make sure we can experiment and test our understanding.
Open your python console and run the code on the right. Make sure you have OpenCV installed.
You've just written your first edge detector with MLBLR!
ML and AI
We use Tensorflow and Keras. But you're free to use platform of your choice!
# function-API driven CNN for character recognition on MNIST dataset inputs = Input(shape=(28, 28, 1)) X = Conv2D(32, (3, 3), padding = 'same', activation='relu')(inputs) X = Conv2D(64, (3, 3), activation='relu')(X) X = MaxPooling2D((2, 2))(X) X = Dropout(0.25)(X) X = Flatten()(X) X = Dense(196, activation='relu')(X) recon = MaxPooling2D((2, 2))(inputs) recon = Reshape((196,), input_shape=(28, 28))(recon) X = Add()([recon, X]) X = Dropout(0.5)(X) output = Dense(num_classes, activation='softmax')(X) model = Model(inputs=[inputs], outputs=[output]) model.summary()
As a group we are teaching and learning end-to-end concepts in Machine Learning and Artificial Intelligence.
Our group hosts hands-on sessions periodically where we cover these concepts in depths. Our sessions runs in to 4-5 hours each time and is interactive and not monologues, where every question gets answered. Each time first hour is dedicated for basics, so no new member is left behind.
Also as a meetup group, our aim is not to call industry experts and listen just to the potential of ML & AI. We want MLBLR community to get their hands dirty and understand deeper concepts behind the art of ML&AI.
ML&AI capable GPUs are hard to come by, and for hands-on sessions, it is nearly impossible to use the GPU in the laptops for real-time learning.
We leverage Google Colab to make sure every one of us can run at least CIFAR level dataset/algorithms. We encourage you to open an account with Google Colab and request for GPU access.
You are free to use any platform of your choice, keras is just very simple to begin with.
Run this code to generate random number plates
# Several things to consider to create "real" NP dataset # Download ttf font you want to use # Install PIL # This code will only generate simple number plates # We further perform post-processing in Blender to create skewed/ # tilted/scaled and motion-blurred number plates. from PIL import ImageFont, ImageDraw, Image import numpy as np import cv2 import random # ASCII A to Z are 65 to 90 hel = [75, 25, 15, 130, 120] beb = [110, 2, 60, 135, 150] #use a truetype font #font = ImageFont.truetype("Helvetica-Bold.ttf", 120) font = ImageFont.truetype("BebasNeueBold.ttf", 150) rtc = 67 bias = 10 for r in range(rtc+1): if r < 4: for k in range(1000): if r < 10: number_plate_1 = "KA 0" + str(r) else: number_plate_1 = "KA " + str(r) number_plate_2 = (chr(random.randint(65, 90))+chr(random.randint(65, 90))+" " + str(random.randint(1000, 9999))) img = np.zeros((256, 512, 3), np.uint8) pil_img = Image.fromarray(img) draw = ImageDraw.Draw(pil_img) draw.text((75, 25), number_plate_1, font=font) draw.text((15, 130), number_plate_2, font=font) cv2_img = cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGB2BGR) cv2_img = cv2.bitwise_not(cv2_img) #cv2.imshow("number_plate", cv2_img) cv2.imwrite(number_plate_1+" "+number_plate_2+".png", cv2_img) #cv2.waitKey(10) else: for k in range(100): if r < 10: number_plate_1 = "KA 0" + str(r) else: number_plate_1 = "KA " + str(r) number_plate_2 = (chr(random.randint(65, 90))+chr(random.randint(65, 90))+" " + str(random.randint(1000, 9999))) img = np.zeros((256, 512, 3), np.uint8) pil_img = Image.fromarray(img) draw = ImageDraw.Draw(pil_img) draw.text((75, 25), number_plate_1, font=font) draw.text((15, 130), number_plate_2, font=font) cv2_img = cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGB2BGR) cv2_img = cv2.bitwise_not(cv2_img) #cv2.imshow("number_plate", cv2_img) cv2.imwrite(number_plate_1+" "+number_plate_2+".png", cv2_img) #cv2.waitKey(10) cv2.destroyAllWindows()
Our first community project is ANPR (Automatic Number Plate Recognition) for Indian number plates. As the group learns further, the contributors would be assigned Project roles and responsibilities.
Currently the group recommends to build:
- Facial Recognition
- Image Captioning
projects first, before initiating several more targets.
Currently, we are in the process to collect and annotate number plate images. Once this process is near completion we will initiate the ANPR project.
Current ANPR solutions are not robust in real-world situations. We aim to create a:
- robust ANPR end-to-end solution
- trained on our dataset
- trained on SSIG
- trained on UFPR-ALPR dataset
- capable of running at 45 fps, with
- accuracy target of 80%.
Current state of art runs at 78.33% at 35 FPS.
Simulated NPs using OpenCV and Blender3D
As an MLBLR community, we are collectively creating an Indian Number Plate database. The aim is to create a database of 100k real Number Plates and 100k simulated number plates.
Once the data is annotated and cleaned, it will be uploaded online for others to make use of.
Simulated Number Plates
We are extending our number plate database through simulation. We have created a pipeline to add 100k additional images to our original database.
A simulated database allows us to:
- Create different viewing angles for the same image
- Create a distraction-free "easy" database without noise or backgrounds
- Create a database not dependent on camera noise and allow for perfect scaling
- Create as many databases for any Indian State as we want
- Study the performance on real-dataset and augment with more Number Plate styles for "hard" images/cases
We will also be creating World's biggest Vehicle Database (focused on Indian vehicles). Target is to reach 100k images.
All the meet-ups are paid but in kind. If you are going to attend any HandsOn meetup session, please take 5 minutes to take 25 images of vehicle number plates around you! That's all it takes to build this community and contribute back!
Global and Adaptive Thresholding example
import cv2 as cv import numpy as np from matplotlib import pyplot as plt img = cv.imread('sudoku.png',0) # replace this with your image img = cv.medianBlur(img,5) ret,th1 = cv.threshold(img,127,255,cv.THRESH_BINARY) th2 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_MEAN_C,\ cv.THRESH_BINARY,11,2) th3 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv.THRESH_BINARY,11,2) titles = ['Original Image', 'Global Thresholding (v = 127)', 'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding'] images = [img, th1, th2, th3] for i in xrange(4): plt.subplot(2,2,i+1),plt.imshow(images[i],'gray') plt.title(titles[i]) plt.xticks(),plt.yticks() plt.show()
We are always looking for contributors. You can contribute in several ways:
- write content for mlblr.com
- collect Number Plate images
- share your code back with the community
- add comments to the code blocks
- review the content on this site for mistakes and bugs
- share awesome new papers to be added to "Research Papers" section
- suggest content for future website updates
- create and help us host Data Collection Tools (like image captioning, image tagging, etc.)
- recommend speakers for future sessions
- host a meetup yourself! And finally,
- teach others!
Don't forget to spread the word about MLBLR.com.
AI and India
Code to read an online image in python
import numpy as np from urllib.request import urlopen import cv2 url_link = urlopen("https://images.mapsofindia.com/my-india/2016/12/Is-Artificial-Intelligence-the-Real-Thing-for-India.jpg") image = np.asarray(bytearray(url_link.read())) image = cv2.imdecode(image, cv2.IMREAD_COLOR) cv2.imshow("Image", image) cv2.waitKey(0)
AI/ML will soon wipe out most of the mediocre jobs. Chatbots, Video Analytics ML Algorithms, Medical and Health, Banking and Legal Documentation Review Algorithms, etc. are already here. These algorithms are immensely helpful and potential application of AI/ML is huge.
Instead of fighting for "labor-rights" later on, it makes much more sense for India to adopt and lead AI/ML research and create more jobs in this field! Moreover, the world is not going to wait for us to catch on in future. China has already displaced US and other western countries as a leader in ML&AI research. It's time we buckle up!
These core sentiments are the force driving MLBLR.com.
You can contact us on slack, or email us at machinelearningblr at gmail.com.