| | import numpy as np |
| |
|
| | |
| | def get_predictions(model,img,return_raw = False): |
| |
|
| | width,height,_ = img.shape |
| | |
| | results = model(img,size=512) |
| | |
| | output = results.xyxy[0] |
| | |
| | |
| | bbox_img = results.show() |
| | |
| | output_arr = output.numpy() |
| | |
| | results = [] |
| | |
| | if(not np.any(output_arr)): |
| | if(return_raw): |
| | return img,results |
| | return results |
| |
|
| | every_monument = ['badrinath temple', 'basantapur tower', 'bhagavati temple', 'bhairavnath temple', 'bhaktapur tower', |
| | 'bhimeleshvara', 'bhimsen temple', 'bhupatindra malla column', 'bhuvana lakshmeshvara', 'chasin dega', |
| | 'chayasilin mandap', 'dattatreya temple', 'degu tale temple_KDS', 'fasidega temple', 'gaddi durbar', |
| | 'garud', 'golden gate', 'gopinath krishna temple', 'hanuman idol', 'indrapura', 'jagannatha temple', |
| | 'kala-bhairava', 'kasthamandap', 'kavindrapura sattal', 'kedamatha tirtha', 'kirtipur tower', 'kumari ghar', |
| | 'lalitpur tower', 'mahadev temple', 'narayan temple', 'national gallery', 'nyatapola temple', |
| | 'palace of the 55 windows', 'panchamukhi hanuman', 'pratap malla column', 'shiva temple', |
| | 'shveta bhairava', 'siddhi lakshmi temple', 'simha sattal', 'taleju bell_BDS', 'taleju bell_KDS', |
| | 'taleju temple', 'trailokya mohan', 'vastala temple', 'vishnu temple', 'bhimsen temple_PDS', |
| | 'char narayan temple', 'chyasim deval', 'garud statue', 'harishankar temple', 'krishna mandir', |
| | 'mani ganesh temple', 'mani mandap', 'royal palace_PDS', 'taleju bell_PDS', 'taleju temple north', |
| | 'taleju temple south', 'vishwanath temple', 'yognarendra malla statue'] |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | THRESHOLD = 0.45 |
| | if(return_raw) : THRESHOLD = 0.0 |
| | |
| | output_arr1 = [] |
| |
|
| | i_count = 0 |
| | for i in output_arr: |
| | |
| | if ( i[4] < THRESHOLD): continue |
| | |
| | high = i |
| | |
| | |
| | hit_pos = -1 |
| | j_count = 0 |
| | for j in output_arr: |
| | |
| | if j[5] == high[5] and j[4] > high[4]: |
| | high = j |
| | hit_pos = j_count |
| | j_count += 1 |
| | i_count += 1 |
| |
|
| | |
| | if(hit_pos == -1): |
| | output_arr1.append(high) |
| | |
| | if(hit_pos > i_count): |
| | output_arr1.append(high) |
| |
|
| |
|
| | |
| | for i in output_arr1: |
| | temp = {"rect" : { "w" : (i[2]-i[0]) / width , |
| | "x" : i[0] / width , |
| | "h" : (i[3]-i[1]) / height , |
| | "y" : i[1] / height, |
| | }, |
| | "confidenceInClass" : float(i[4]), |
| | "DetectedClass" : every_monument[int(i[5])] |
| | } |
| | results.append(temp) |
| | |
| | |
| | |
| |
|
| | |
| | if(return_raw): |
| | return bbox_img,results |
| | |
| |
|
| | return results |
| |
|