Reputation:
I have used Convolutional Neural Network(CNN) to train the legends in the maps. These legends are circles, ovals, diamonds, crosses, and squares. The neural network (inspired from the code https://towardsdatascience.com/from-raw-images-to-real-time-predictions-with-deep-learning-ddbbda1be0e4) works well in my case. The input images are individual cropped pictures of legends like input trained image and the output I want is to predict these legends in the maps like input maps. My neural network can now classify the images and predict whether they are squares or circles. For example, when I provided this image diamondinput as input, the output is diamond.
from keras.models import model_from_json
import numpy as np
EMOTIONS_LIST = ["circle","cross","diamond","oval","square"]
def predict_emotion(img):
preds = model.predict(img)
return EMOTIONS_LIST[np.argmax(preds)]
import cv2
import numpy as np
from google.colab.patches import cv2_imshow
import keras
#model = keras.models.load_model('/content/drive/MyDrive/model_weights_updated.h5')
fr=cv2.imread('/content/drive/MyDrive/Images/train/diamond/Copy of 0076.tif')
gray_fr = cv2.cvtColor(fr, cv2.COLOR_BGR2GRAY)
roi = cv2.resize(gray_fr, (48, 48))
pred = predict_emotion(roi[np.newaxis, :, :, np.newaxis])
print(pred)
Output for the program:
[[1.7809551e-06 2.4862277e-07 9.9999583e-01 2.1272169e-06 8.9550163e-09]], diamond
How can I make the neural network to predict these legends in the map and all other legends in the map like this outputmap?.
Upvotes: 0
Views: 341
Reputation: 111
With the network you got, it would be possible to just split each map into a grid and then perform classification for each segment in the grid, but there are many problems with such an approach.
A better solution for you would be to use a neural network that does semantic segmentation. This way, your network regresses a likelihood-map for each of your shapes on the map. With this likelihood-map, you will know how many you have of each class and where they are.
To do so, you can start with the following MaskRCNN implementation.
https://github.com/matterport/Mask_RCNN
Upvotes: 0