Skip to content
Snippets Groups Projects
Commit 89833993 authored by ABDERRAHIM El Habib's avatar ABDERRAHIM El Habib
Browse files

Upload New File

parent b30834fd
No related branches found
No related tags found
1 merge request!1uploading main
Main.py 0 → 100644
#basic imports
import numpy as np
import cv2
import Model
import WeightReader
import Load_image
import Process_predictions
import pandas as pd
Model = Model.make_yolov3_model()
weight_reader = WeightReader("yolov3.weights")
weight_reader.load_weights(Model)
input_w, input_h = 416, 416 # here put the size of your input image
photo_filename = 'birds9.jpg' # here put the filename of your input image
image, image_w, image_h = Load_image.load_image_pixels(photo_filename, (input_w, input_h))
outputs = Model.predict(image)
anchors = [[116,90, 156,198, 373,326], [30,61, 62,45, 59,119], [10,13, 16,30, 33,23]]
class_threshold = 0.6
boxes = list()
for i in range(len(outputs)):
boxes += Process_predictions.decode_netout(outputs[i][0], anchors[i], class_threshold, input_h, input_w)
Process_predictions.correct_yolo_boxes(boxes, image_h, image_w, input_h, input_w)
Process_predictions.do_nms(boxes, 0.5)
labels = ["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck",
"boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench",
"bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe",
"backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard",
"sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana",
"apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake",
"chair", "sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse",
"remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator",
"book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"]
v_boxes, v_labels, v_scores = Process_predictions.get_boxes(boxes, labels, class_threshold)
#view our detections
Process_predictions.draw_boxes(photo_filename, v_boxes, v_labels, v_scores)
csv_array = np.zeros((len(v_boxes),5))
# this code creates an array in which we save the coordinates of the rectangles: the detected birds
id_image = 0 # i still don't know how to fill up image ids
from PIL import Image
#for j in range( number of images )
for i in range(len(v_boxes)):
csv_array[i][0]=i
csv_array[i][1]=v_boxes[i].xmin
csv_array[i][2]=v_boxes[i].ymax
csv_array[i][3]=v_boxes[i].xmax
csv_array[i][4]=v_boxes[i].ymin
# we convert our array to a dataframe and then we save it in a csv file
import pandas as pd
pd.DataFrame(csv_array).to_csv('sample.csv')
#now we will reload our original image and crop the detected birds and save them in different files
img = cv2.imread('birds9.jpg') # insert original image here
print(img.shape) # Print image shape
for i in range(len(v_boxes)):
cropped_image = img[v_boxes[i].ymin:v_boxes[i].ymax, v_boxes[i].xmin:v_boxes[i].xmax]
cv2.imwrite("oiseau " + str(i+1) + ".jpg", cropped_image)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment