-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Extracting coordinates instead of drawing a box #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm facing the same problem. Do you have a solution for this? Mind to share? |
I found a solution. I'll share it on here tomorrow, when I'm at work (don't have the solution at home). |
add this to the utils/visualization_utils.py
add this to Object_detection_dir.py
as well as this:
I think this should be all. |
This was very helpful. thank you so much. coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100)]) into and you can access each ymin, ymax , xmin, xmax values separately using ymin=coordinate_list[0] etc. in your object detection file. |
@PraveenNellihela I have been getting an error of IndexError: list index out of range coordinates = vis_util.return_coordinates( |
Try using some form of error handling such as "try and except". You are most likely getting this error when there are no detections. I think I got the same issue when I was doing this, when the object I was trying to detect went out of the video frame. I used "try and except" to ignore the values when there werent any so it didnt produce an error. Hope this helps. |
@PraveenNellihela Thank you for the suggestion,it worked flawlessly. Best of luck in life. |
@iqrammm Can you share the code that you wrote? like how to make "try and except" in this situation |
try:
coordinates = vis_util.return_coordinates(
frame,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=10,
min_score_thresh=0.85)
ymin=int(coordinates[0])
ymax=int(coordinates[1])
xmin=int(coordinates[2])
xmax=int(coordinates[3])
except:
pass
…On Mon, Jul 8, 2019 at 1:47 PM KwonJoo ***@***.***> wrote:
@iqrammm <https://github.com/iqrammm> Can you share the code that you
wrote? like how to make "try and except" in this situation
thanks a lot :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69?email_source=notifications&email_token=ALTHKYXAWREYWALRAG5WBW3P6LIGRA5CNFSM4FFF37G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZMA5ZY#issuecomment-509087463>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALTHKYUBUOIU34JTEPMM77LP6LIGRANCNFSM4FFF37GQ>
.
|
Thanks a lot :)
I couldn't solve this problems until yesterday.
You made my day, sir!
Have a good day and May I email you when I get in trouble?
-----Original Message-----
From: "iqrammm"<notifications@github.com>
To: "EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10"<TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10@noreply.github.com>;
Cc: "KwonJoo"<tobehumble22@naver.com>; "Comment"<comment@noreply.github.com>;
Sent: 2019-07-08 (월) 19:51:07 (GMT+09:00)
Subject: Re: [EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10] Extracting coordinates instead of drawing a box (#69)
try:
coordinates = vis_util.return_coordinates(
frame,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=10,
min_score_thresh=0.85)
ymin=int(coordinates[0])
ymax=int(coordinates[1])
xmin=int(coordinates[2])
xmax=int(coordinates[3])
except:
pass
On Mon, Jul 8, 2019 at 1:47 PM KwonJoo ***@***.***> wrote:
@iqrammm <https://github.com/iqrammm> Can you share the code that you
wrote? like how to make "try and except" in this situation
thanks a lot :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69?email_source=notifications&email_token=ALTHKYXAWREYWALRAG5WBW3P6LIGRA5CNFSM4FFF37G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZMA5ZY#issuecomment-509087463>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALTHKYUBUOIU34JTEPMM77LP6LIGRANCNFSM4FFF37GQ>
.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Sure but I may not be able to answer as I am also pretty new to tensorflow
and dnn
…On Tue, Jul 9, 2019 at 8:36 AM KwonJoo ***@***.***> wrote:
Thanks a lot :)
I couldn't solve this problems until yesterday.
You made my day, sir!
Have a good day and May I email you when I get in trouble?
-----Original Message-----
From: ***@***.***>
To:
"EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10"<
***@***.***
>;
Cc: ***@***.***>; "Comment"<
***@***.***>;
Sent: 2019-07-08 (월) 19:51:07 (GMT+09:00)
Subject: Re:
[EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10]
Extracting coordinates instead of drawing a box (#69)
try:
coordinates = vis_util.return_coordinates(
frame,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=10,
min_score_thresh=0.85)
ymin=int(coordinates[0])
ymax=int(coordinates[1])
xmin=int(coordinates[2])
xmax=int(coordinates[3])
except:
pass
On Mon, Jul 8, 2019 at 1:47 PM KwonJoo ***@***.***> wrote:
> @iqrammm <https://github.com/iqrammm> Can you share the code that you
> wrote? like how to make "try and except" in this situation
> thanks a lot :)
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#69?email_source=notifications&email_token=ALTHKYXAWREYWALRAG5WBW3P6LIGRA5CNFSM4FFF37G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZMA5ZY#issuecomment-509087463
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/ALTHKYUBUOIU34JTEPMM77LP6LIGRANCNFSM4FFF37GQ
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69?email_source=notifications&email_token=ALTHKYUJW3XDLYF3IW2RFTLP6PMRRA5CNFSM4FFF37G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZOXSQQ#issuecomment-509442370>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALTHKYVBFYV7KJPOMSX5UWDP6PMRRANCNFSM4FFF37GQ>
.
|
@PraveenNellihela Do you by any chance know how to return the percentage scores as well? I added to return scores but cant seem to get it to work. |
Hey, the code I originally posted should already return the class that was detected and the accuracy in percent. You can get all 6 values from the return like this:
With "accuracy" being the value you are looking for and "classification" the ID you associated with your object's class. EDIT:
int(class_name) should contain the ID of the detected object. EDIT 2:
|
@iqrammm in your case, with the changes you made to the return_coordinates function, it would be something like this:
I haven't tested the code above, but theoretically it should work like that, since the return_coordinates function returns a list with ymin, ymax, xmin, xmax, accuracy. The (box_to_score_map[box]*100) is the accuracy in percentage. |
I believe this not complete since class_name will return the last class that was assigned to the variable. |
UPDATE: I figured out how to write the values to a text file by making some modifications in the last few lines of the object_detection.py file! Thank you @psi43 I'm facing issues with these lines (writing the coordinates into the text file) does the filename_string simply refer to an empty text file that I should create to save the outputs? |
I'll try to look into this. I use this code daily and have heavily modified it since (my example does work for me, but I might have missed a change). So me looking it up a few weeks ago might be very different to what I posted months ago.
filename_string is a variable I used to write the coordinates to a json file. I was very new to python and was frustrated that building the filename out of strings and integers didn't work, so I had to do that and then cast the variable to a string. Hence the name. |
I got it working. The piece that you have modified for your use case it is open source ? |
Sadly no. Even if I planned on making it open source, I'd probably have to make a lot of changes, due to dumb variable names like "filename_string" and general bad code. Glad you got yours to work though! If you (or anyone else) has any more questions, I'll definitely try and answer them as best I can. |
@SKY24 Can you please advise on how to fix the issue you pointed out earlier? 'class_name will return the last class that was assigned to the variable' |
make the following change sand it should work `if agnostic_mode:
|
It`s an amazing thread for my work also. I have another question regarding ### object_detection_image.py###. After finishing the training session, I want to read a folder of image files and do detection issues on them but instead of showing them, the results are saved as image filename and detection score in a file (.csv maybe). Could anyone help me with my problem? Best, |
Hello @psi43 , There is no Object_detection_dir.py, so where do i have to add this code? coordinates = vis_util.return_coordinates( textfile = open("json/"+filename_string+".json", "a") |
Hello @psi43 , for coordinate in coordinates: But there are multiple images of same label that i want to crop. Thanks and Regards. :) |
@SinaMojtahedi In the example I gave for cropping, where I loop through the coordinates, you could replace that with writing the coordinates and other info into a .csv file. That was actually the natural progression of my project as well, instead of cropping one image, I now go through a directory of images and extract all the coordinates and save them in a .json file with the same name as the image. @hiteshreddy95 Sorry, I made an Object_detection_dir.py by basically putting a huge for-loop around the Object_detection_image.py so it would cycle through an entire directory of images. @akshay-bahulikar With that for-loop, it should crop out every object. Keep in mind, that you would have to implement a counter or something so the filename changes every time. Like crop_1.jpg, crop_2.jpg, etc. If you just name it crop.jpg, it will only be the last object recognized, because it would keep replacing crop.jpg with every iteration. |
Hi I'm new at the python language and TF tool so sorry for my dump question 🙋 |
@MousaAlnajjar I believe it does, I can't remember for sure. But I seem to remember needing to remove them because they were saved as part of the image, not entirely sure though. If you do want the boxes, just look at the lines below: |
I'll try it, but I want to ask you another question |
@psi43 There is a weird contradiction I came across when there is multi object detection ... I'm doing rock, paper, scissor detection ... so if I use and this is the classification:
representing y1, y2, x1, x2, accuracy, classification respectively |
[[483.25], [681.0], ['VO: 99%'], 'V'] |
IMAGENAME BOXCENTRLPOINT Y-MP C-A
0 cap_000 [[616.0]
[821.0] 'VO: 87%']
this is my return coordinates . but i have to vo is separate column and
accrue 87% is separate column.
how is possible?
how is change in visualization.until code?
…On Fri, 19 Jun 2020 at 12:59, psi43 ***@***.***> wrote:
@jix1710 <https://github.com/jix1710> I haven't looked into that at all,
but a quick google came up with this:
https://xlsxwriter.readthedocs.io/
Seems like you'd be able to output as xlsx instead of json with this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOQW3D4Q35TSYBF5AJYHYJLRXMHVDANCNFSM4FFF37GQ>
.
|
i use your return coordinates code..
…On Sun, 21 Jun 2020 at 11:50, jix italiya ***@***.***> wrote:
IMAGENAME BOXCENTRLPOINT Y-MP C-A
0 cap_000 [[616.0]
[821.0] 'VO: 87%']
this is my return coordinates . but i have to vo is separate column and
accrue 87% is separate column.
how is possible?
how is change in visualization.until code?
On Fri, 19 Jun 2020 at 12:59, psi43 ***@***.***> wrote:
> @jix1710 <https://github.com/jix1710> I haven't looked into that at all,
> but a quick google came up with this:
> https://xlsxwriter.readthedocs.io/
>
> Seems like you'd be able to output as xlsx instead of json with this.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#69 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOQW3D4Q35TSYBF5AJYHYJLRXMHVDANCNFSM4FFF37GQ>
> .
>
|
1.import some models:
2.markdown default IMAGE PATH: 3.And heres the change:
|
hii my out IMAGENAME BOXCENTRLPOINT Y-MP C-A |
@jix1710 I'm sorry, but I don't understand what you're trying to ask :(. |
|
how is possible to find the object detection output data is right ya wrong? |
How to call all Images open at once time ? |
Hey man! i don't know if it's right.
|
thx bro .And heres the change:
for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
print("\n")
print("Start parsing "+filename+"...")
image = cv2.imread(filename)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_expanded = np.expand_dims(image_rgb, axis=0)
this is run for me but how all image show after detection?
bs of ths folder in 30 image but only one image is showme output
…On Wed, 15 Jul 2020 at 10:41, Sn0wl3r0ker ***@***.***> wrote:
如何一次調用所有圖像?
在物體檢測模型中
Hey man! i don't know if it's right.
But i think u can try my "for loop" method to call all images in the
target folder.
add this to the utils/visualization_utils.py
def return_coordinates(
image,
boxes,
classes,
scores,
category_index,
instance_masks=None,
instance_boundaries=None,
keypoints=None,
use_normalized_coordinates=False,
max_boxes_to_draw=20,
min_score_thresh=.5,
agnostic_mode=False,
line_thickness=4,
groundtruth_box_visualization_color='black',
skip_scores=False,
skip_labels=False):
# Create a display string (and color) for every box location, group any boxes
# that correspond to the same location.
box_to_display_str_map = collections.defaultdict(list)
box_to_color_map = collections.defaultdict(str)
box_to_instance_masks_map = {}
box_to_instance_boundaries_map = {}
box_to_score_map = {}
box_to_keypoints_map = collections.defaultdict(list)
if not max_boxes_to_draw:
max_boxes_to_draw = boxes.shape[0]
for i in range(min(max_boxes_to_draw, boxes.shape[0])):
if scores is None or scores[i] > min_score_thresh:
box = tuple(boxes[i].tolist())
if instance_masks is not None:
box_to_instance_masks_map[box] = instance_masks[i]
if instance_boundaries is not None:
box_to_instance_boundaries_map[box] = instance_boundaries[i]
if keypoints is not None:
box_to_keypoints_map[box].extend(keypoints[i])
if scores is None:
box_to_color_map[box] = groundtruth_box_visualization_color
else:
display_str = ''
if not skip_labels:
if not agnostic_mode:
if classes[i] in category_index.keys():
class_name = category_index[classes[i]]['name']
else:
class_name = 'N/A'
display_str = str(class_name)
if not skip_scores:
if not display_str:
display_str = '{}%'.format(int(100*scores[i]))
else:
display_str = '{}: {}%'.format(display_str, int(100*scores[i]))
box_to_display_str_map[box].append(display_str)
box_to_score_map[box] = scores[i]
if agnostic_mode:
box_to_color_map[box] = 'DarkOrange'
else:
box_to_color_map[box] = STANDARD_COLORS[
classes[i] % len(STANDARD_COLORS)]
# Draw all boxes onto image.
coordinates_list = []
counter_for = 0
for box, color in box_to_color_map.items():
ymin, xmin, ymax, xmax = box
height, width, channels = image.shape
ymin = int(ymin*height)
ymax = int(ymax*height)
xmin = int(xmin*width)
xmax = int(xmax*width)
coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100)])
counter_for = counter_for + 1
return coordinates_list
add this to Object_detection_dir.py
coordinates = vis_util.return_coordinates(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8,
min_score_thresh=0.80)
as well as this:
textfile = open("json/"+filename_string+".json", "a")
textfile.write(json.dumps(coordinates))
textfile.write("\n")
I think this should be all.
Hi! This is not a issue.I add this simple loop to make the code detect all
.JPG file the the testimg folder and export the .json file, img with boxes
in json, json/testimg folder. Hope this can help someone who wants it....
P.S. i'm still a noob, so hope u can give me some advise
1.import some models:
import glob
import re
2.markdown default IMAGE PATH:
"# IMAGE_NAME ="
"# PATH_TO_IMAGE = os.path.join(CWD_PATH,IMAGE_NAME)"
3.And heres the change:
for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
print("\n")
print("Start parsing "+filename+"...")
image = cv2.imread(filename)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_expanded = np.expand_dims(image_rgb, axis=0)
filenameJ = re.sub(r".*?\/", "", filename)
open("json/"+filenameJ+".json", "a").write(json.dumps(coordinates)+"\n"
for coordinate in coordinates:
(y1, y2, x1, x2, acc, classification) = coordinate
height = y2-y1
width = x2-x1
crop = image[y1:y1+height, x1:x1+width]
cv2.imwrite("json/"+filename, image)
print(coordinate)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOQW3D2SG7CMQSCAR3KNKH3R3U3BPANCNFSM4FFF37GQ>
.
|
Start parsing test_images\Cap_6.jpg...
Start parsing test_images\Cap_7.jpg...
Start parsing test_images\Cap_8.jpg...
Start parsing test_images\Cap_9.jpg...
[502.5, 864.0, 'VO: 99%']
how is all image output cap_9 type?
…On Wed, 15 Jul 2020 at 16:13, jix italiya ***@***.***> wrote:
thx bro .And heres the change:
for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
print("\n")
print("Start parsing "+filename+"...")
image = cv2.imread(filename)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_expanded = np.expand_dims(image_rgb, axis=0)
this is run for me but how all image show after detection?
bs of ths folder in 30 image but only one image is showme output
On Wed, 15 Jul 2020 at 10:41, Sn0wl3r0ker ***@***.***>
wrote:
> 如何一次調用所有圖像?
> 在物體檢測模型中
>
> Hey man! i don't know if it's right.
> But i think u can try my "for loop" method to call all images in the
> target folder.
>
> add this to the utils/visualization_utils.py
>
> def return_coordinates(
>
> image,
>
> boxes,
>
> classes,
>
> scores,
>
> category_index,
>
> instance_masks=None,
>
> instance_boundaries=None,
>
> keypoints=None,
>
> use_normalized_coordinates=False,
>
> max_boxes_to_draw=20,
>
> min_score_thresh=.5,
>
> agnostic_mode=False,
>
> line_thickness=4,
>
> groundtruth_box_visualization_color='black',
>
> skip_scores=False,
>
> skip_labels=False):
>
> # Create a display string (and color) for every box location, group any boxes
>
> # that correspond to the same location.
>
> box_to_display_str_map = collections.defaultdict(list)
>
> box_to_color_map = collections.defaultdict(str)
>
> box_to_instance_masks_map = {}
>
> box_to_instance_boundaries_map = {}
>
> box_to_score_map = {}
>
> box_to_keypoints_map = collections.defaultdict(list)
>
> if not max_boxes_to_draw:
>
> max_boxes_to_draw = boxes.shape[0]
>
> for i in range(min(max_boxes_to_draw, boxes.shape[0])):
>
> if scores is None or scores[i] > min_score_thresh:
>
> box = tuple(boxes[i].tolist())
>
> if instance_masks is not None:
>
> box_to_instance_masks_map[box] = instance_masks[i]
>
> if instance_boundaries is not None:
>
> box_to_instance_boundaries_map[box] = instance_boundaries[i]
>
> if keypoints is not None:
>
> box_to_keypoints_map[box].extend(keypoints[i])
>
> if scores is None:
>
> box_to_color_map[box] = groundtruth_box_visualization_color
>
> else:
>
> display_str = ''
>
> if not skip_labels:
>
> if not agnostic_mode:
>
> if classes[i] in category_index.keys():
>
> class_name = category_index[classes[i]]['name']
>
> else:
>
> class_name = 'N/A'
>
> display_str = str(class_name)
>
> if not skip_scores:
>
> if not display_str:
>
> display_str = '{}%'.format(int(100*scores[i]))
>
> else:
>
> display_str = '{}: {}%'.format(display_str, int(100*scores[i]))
>
> box_to_display_str_map[box].append(display_str)
>
> box_to_score_map[box] = scores[i]
>
> if agnostic_mode:
>
> box_to_color_map[box] = 'DarkOrange'
>
> else:
>
> box_to_color_map[box] = STANDARD_COLORS[
>
> classes[i] % len(STANDARD_COLORS)]
>
>
>
> # Draw all boxes onto image.
>
> coordinates_list = []
>
> counter_for = 0
>
> for box, color in box_to_color_map.items():
>
> ymin, xmin, ymax, xmax = box
>
> height, width, channels = image.shape
>
> ymin = int(ymin*height)
>
> ymax = int(ymax*height)
>
> xmin = int(xmin*width)
>
> xmax = int(xmax*width)
>
> coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100)])
>
> counter_for = counter_for + 1
>
>
>
> return coordinates_list
>
>
> add this to Object_detection_dir.py
>
> coordinates = vis_util.return_coordinates(
>
> image,
>
> np.squeeze(boxes),
>
> np.squeeze(classes).astype(np.int32),
>
> np.squeeze(scores),
>
> category_index,
>
> use_normalized_coordinates=True,
>
> line_thickness=8,
>
> min_score_thresh=0.80)
>
>
> as well as this:
>
> textfile = open("json/"+filename_string+".json", "a")
>
> textfile.write(json.dumps(coordinates))
>
> textfile.write("\n")
>
>
> I think this should be all.
> Hi! This is not a issue.I add this simple loop to make the code detect
> all .JPG file the the testimg folder and export the .json file, img with
> boxes in json, json/testimg folder. Hope this can help someone who wants
> it.... P.S. i'm still a noob, so hope u can give me some advise
>
> 1.import some models:
>
> import glob
>
> import re
>
>
> 2.markdown default IMAGE PATH:
> "# IMAGE_NAME ="
> "# PATH_TO_IMAGE = os.path.join(CWD_PATH,IMAGE_NAME)"
>
> 3.And heres the change:
>
> for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
>
> print("\n")
>
> print("Start parsing "+filename+"...")
>
> image = cv2.imread(filename)
>
> image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
>
> image_expanded = np.expand_dims(image_rgb, axis=0)
>
>
> filenameJ = re.sub(r".*?\/", "", filename)
>
> open("json/"+filenameJ+".json", "a").write(json.dumps(coordinates)+"\n"
>
>
>
> for coordinate in coordinates:
>
> (y1, y2, x1, x2, acc, classification) = coordinate
>
> height = y2-y1
>
> width = x2-x1
>
> crop = image[y1:y1+height, x1:x1+width]
>
> cv2.imwrite("json/"+filename, image)
>
> print(coordinate)
>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#69 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOQW3D2SG7CMQSCAR3KNKH3R3U3BPANCNFSM4FFF37GQ>
> .
>
|
how to solve this problem ? i have use this code ([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100),display_strs[counter_for]]) but output coordinates same class name not to multi class find |
i have collected some 300 different classes of objects. But when I run the
program, only 1 images were detected, the remaining 299 images were not
detected. and only show 1 ige coordinates Please let me know, why the rest
of the images were not detecting..
REPLY
…On Wed, 15 Jul 2020 at 16:33, jix italiya ***@***.***> wrote:
Start parsing test_images\Cap_6.jpg...
Start parsing test_images\Cap_7.jpg...
Start parsing test_images\Cap_8.jpg...
Start parsing test_images\Cap_9.jpg...
[502.5, 864.0, 'VO: 99%']
how is all image output cap_9 type?
On Wed, 15 Jul 2020 at 16:13, jix italiya ***@***.***> wrote:
> thx bro .And heres the change:
>
> for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
>
> print("\n")
>
> print("Start parsing "+filename+"...")
>
> image = cv2.imread(filename)
>
> image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
>
> image_expanded = np.expand_dims(image_rgb, axis=0)
>
> this is run for me but how all image show after detection?
> bs of ths folder in 30 image but only one image is showme output
>
> On Wed, 15 Jul 2020 at 10:41, Sn0wl3r0ker ***@***.***>
> wrote:
>
>> 如何一次調用所有圖像?
>> 在物體檢測模型中
>>
>> Hey man! i don't know if it's right.
>> But i think u can try my "for loop" method to call all images in the
>> target folder.
>>
>> add this to the utils/visualization_utils.py
>>
>> def return_coordinates(
>>
>> image,
>>
>> boxes,
>>
>> classes,
>>
>> scores,
>>
>> category_index,
>>
>> instance_masks=None,
>>
>> instance_boundaries=None,
>>
>> keypoints=None,
>>
>> use_normalized_coordinates=False,
>>
>> max_boxes_to_draw=20,
>>
>> min_score_thresh=.5,
>>
>> agnostic_mode=False,
>>
>> line_thickness=4,
>>
>> groundtruth_box_visualization_color='black',
>>
>> skip_scores=False,
>>
>> skip_labels=False):
>>
>> # Create a display string (and color) for every box location, group any boxes
>>
>> # that correspond to the same location.
>>
>> box_to_display_str_map = collections.defaultdict(list)
>>
>> box_to_color_map = collections.defaultdict(str)
>>
>> box_to_instance_masks_map = {}
>>
>> box_to_instance_boundaries_map = {}
>>
>> box_to_score_map = {}
>>
>> box_to_keypoints_map = collections.defaultdict(list)
>>
>> if not max_boxes_to_draw:
>>
>> max_boxes_to_draw = boxes.shape[0]
>>
>> for i in range(min(max_boxes_to_draw, boxes.shape[0])):
>>
>> if scores is None or scores[i] > min_score_thresh:
>>
>> box = tuple(boxes[i].tolist())
>>
>> if instance_masks is not None:
>>
>> box_to_instance_masks_map[box] = instance_masks[i]
>>
>> if instance_boundaries is not None:
>>
>> box_to_instance_boundaries_map[box] = instance_boundaries[i]
>>
>> if keypoints is not None:
>>
>> box_to_keypoints_map[box].extend(keypoints[i])
>>
>> if scores is None:
>>
>> box_to_color_map[box] = groundtruth_box_visualization_color
>>
>> else:
>>
>> display_str = ''
>>
>> if not skip_labels:
>>
>> if not agnostic_mode:
>>
>> if classes[i] in category_index.keys():
>>
>> class_name = category_index[classes[i]]['name']
>>
>> else:
>>
>> class_name = 'N/A'
>>
>> display_str = str(class_name)
>>
>> if not skip_scores:
>>
>> if not display_str:
>>
>> display_str = '{}%'.format(int(100*scores[i]))
>>
>> else:
>>
>> display_str = '{}: {}%'.format(display_str, int(100*scores[i]))
>>
>> box_to_display_str_map[box].append(display_str)
>>
>> box_to_score_map[box] = scores[i]
>>
>> if agnostic_mode:
>>
>> box_to_color_map[box] = 'DarkOrange'
>>
>> else:
>>
>> box_to_color_map[box] = STANDARD_COLORS[
>>
>> classes[i] % len(STANDARD_COLORS)]
>>
>>
>>
>> # Draw all boxes onto image.
>>
>> coordinates_list = []
>>
>> counter_for = 0
>>
>> for box, color in box_to_color_map.items():
>>
>> ymin, xmin, ymax, xmax = box
>>
>> height, width, channels = image.shape
>>
>> ymin = int(ymin*height)
>>
>> ymax = int(ymax*height)
>>
>> xmin = int(xmin*width)
>>
>> xmax = int(xmax*width)
>>
>> coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100)])
>>
>> counter_for = counter_for + 1
>>
>>
>>
>> return coordinates_list
>>
>>
>> add this to Object_detection_dir.py
>>
>> coordinates = vis_util.return_coordinates(
>>
>> image,
>>
>> np.squeeze(boxes),
>>
>> np.squeeze(classes).astype(np.int32),
>>
>> np.squeeze(scores),
>>
>> category_index,
>>
>> use_normalized_coordinates=True,
>>
>> line_thickness=8,
>>
>> min_score_thresh=0.80)
>>
>>
>> as well as this:
>>
>> textfile = open("json/"+filename_string+".json", "a")
>>
>> textfile.write(json.dumps(coordinates))
>>
>> textfile.write("\n")
>>
>>
>> I think this should be all.
>> Hi! This is not a issue.I add this simple loop to make the code detect
>> all .JPG file the the testimg folder and export the .json file, img with
>> boxes in json, json/testimg folder. Hope this can help someone who wants
>> it.... P.S. i'm still a noob, so hope u can give me some advise
>>
>> 1.import some models:
>>
>> import glob
>>
>> import re
>>
>>
>> 2.markdown default IMAGE PATH:
>> "# IMAGE_NAME ="
>> "# PATH_TO_IMAGE = os.path.join(CWD_PATH,IMAGE_NAME)"
>>
>> 3.And heres the change:
>>
>> for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
>>
>> print("\n")
>>
>> print("Start parsing "+filename+"...")
>>
>> image = cv2.imread(filename)
>>
>> image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
>>
>> image_expanded = np.expand_dims(image_rgb, axis=0)
>>
>>
>> filenameJ = re.sub(r".*?\/", "", filename)
>>
>> open("json/"+filenameJ+".json", "a").write(json.dumps(coordinates)+"\n"
>>
>>
>>
>> for coordinate in coordinates:
>>
>> (y1, y2, x1, x2, acc, classification) = coordinate
>>
>> height = y2-y1
>>
>> width = x2-x1
>>
>> crop = image[y1:y1+height, x1:x1+width]
>>
>> cv2.imwrite("json/"+filename, image)
>>
>> print(coordinate)
>>
>>
>> —
>> You are receiving this because you were mentioned.
>> Reply to this email directly, view it on GitHub
>> <#69 (comment)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AOQW3D2SG7CMQSCAR3KNKH3R3U3BPANCNFSM4FFF37GQ>
>> .
>>
>
|
hiii sir plz help me
"for filename in sorted(glob.glob("testing/"+ "*.JPG")):"any idla
sorted function use any other functions use? because of sorted
functions use to list of short...i have no use sorted functions..use
any another functions?
…On Mon, 17 Aug 2020 at 10:37, jix italiya ***@***.***> wrote:
i have collected some 300 different classes of objects. But when I run the
program, only 1 images were detected, the remaining 299 images were not
detected. and only show 1 ige coordinates Please let me know, why the rest
of the images were not detecting..
REPLY
On Wed, 15 Jul 2020 at 16:33, jix italiya ***@***.***> wrote:
> Start parsing test_images\Cap_6.jpg...
>
>
> Start parsing test_images\Cap_7.jpg...
>
>
> Start parsing test_images\Cap_8.jpg...
>
>
> Start parsing test_images\Cap_9.jpg...
> [502.5, 864.0, 'VO: 99%']
>
>
> how is all image output cap_9 type?
>
> On Wed, 15 Jul 2020 at 16:13, jix italiya ***@***.***> wrote:
>
>> thx bro .And heres the change:
>>
>> for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
>>
>> print("\n")
>>
>> print("Start parsing "+filename+"...")
>>
>> image = cv2.imread(filename)
>>
>> image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
>>
>> image_expanded = np.expand_dims(image_rgb, axis=0)
>>
>> this is run for me but how all image show after detection?
>> bs of ths folder in 30 image but only one image is showme output
>>
>> On Wed, 15 Jul 2020 at 10:41, Sn0wl3r0ker ***@***.***>
>> wrote:
>>
>>> 如何一次調用所有圖像?
>>> 在物體檢測模型中
>>>
>>> Hey man! i don't know if it's right.
>>> But i think u can try my "for loop" method to call all images in the
>>> target folder.
>>>
>>> add this to the utils/visualization_utils.py
>>>
>>> def return_coordinates(
>>>
>>> image,
>>>
>>> boxes,
>>>
>>> classes,
>>>
>>> scores,
>>>
>>> category_index,
>>>
>>> instance_masks=None,
>>>
>>> instance_boundaries=None,
>>>
>>> keypoints=None,
>>>
>>> use_normalized_coordinates=False,
>>>
>>> max_boxes_to_draw=20,
>>>
>>> min_score_thresh=.5,
>>>
>>> agnostic_mode=False,
>>>
>>> line_thickness=4,
>>>
>>> groundtruth_box_visualization_color='black',
>>>
>>> skip_scores=False,
>>>
>>> skip_labels=False):
>>>
>>> # Create a display string (and color) for every box location, group any boxes
>>>
>>> # that correspond to the same location.
>>>
>>> box_to_display_str_map = collections.defaultdict(list)
>>>
>>> box_to_color_map = collections.defaultdict(str)
>>>
>>> box_to_instance_masks_map = {}
>>>
>>> box_to_instance_boundaries_map = {}
>>>
>>> box_to_score_map = {}
>>>
>>> box_to_keypoints_map = collections.defaultdict(list)
>>>
>>> if not max_boxes_to_draw:
>>>
>>> max_boxes_to_draw = boxes.shape[0]
>>>
>>> for i in range(min(max_boxes_to_draw, boxes.shape[0])):
>>>
>>> if scores is None or scores[i] > min_score_thresh:
>>>
>>> box = tuple(boxes[i].tolist())
>>>
>>> if instance_masks is not None:
>>>
>>> box_to_instance_masks_map[box] = instance_masks[i]
>>>
>>> if instance_boundaries is not None:
>>>
>>> box_to_instance_boundaries_map[box] = instance_boundaries[i]
>>>
>>> if keypoints is not None:
>>>
>>> box_to_keypoints_map[box].extend(keypoints[i])
>>>
>>> if scores is None:
>>>
>>> box_to_color_map[box] = groundtruth_box_visualization_color
>>>
>>> else:
>>>
>>> display_str = ''
>>>
>>> if not skip_labels:
>>>
>>> if not agnostic_mode:
>>>
>>> if classes[i] in category_index.keys():
>>>
>>> class_name = category_index[classes[i]]['name']
>>>
>>> else:
>>>
>>> class_name = 'N/A'
>>>
>>> display_str = str(class_name)
>>>
>>> if not skip_scores:
>>>
>>> if not display_str:
>>>
>>> display_str = '{}%'.format(int(100*scores[i]))
>>>
>>> else:
>>>
>>> display_str = '{}: {}%'.format(display_str, int(100*scores[i]))
>>>
>>> box_to_display_str_map[box].append(display_str)
>>>
>>> box_to_score_map[box] = scores[i]
>>>
>>> if agnostic_mode:
>>>
>>> box_to_color_map[box] = 'DarkOrange'
>>>
>>> else:
>>>
>>> box_to_color_map[box] = STANDARD_COLORS[
>>>
>>> classes[i] % len(STANDARD_COLORS)]
>>>
>>>
>>>
>>> # Draw all boxes onto image.
>>>
>>> coordinates_list = []
>>>
>>> counter_for = 0
>>>
>>> for box, color in box_to_color_map.items():
>>>
>>> ymin, xmin, ymax, xmax = box
>>>
>>> height, width, channels = image.shape
>>>
>>> ymin = int(ymin*height)
>>>
>>> ymax = int(ymax*height)
>>>
>>> xmin = int(xmin*width)
>>>
>>> xmax = int(xmax*width)
>>>
>>> coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100)])
>>>
>>> counter_for = counter_for + 1
>>>
>>>
>>>
>>> return coordinates_list
>>>
>>>
>>> add this to Object_detection_dir.py
>>>
>>> coordinates = vis_util.return_coordinates(
>>>
>>> image,
>>>
>>> np.squeeze(boxes),
>>>
>>> np.squeeze(classes).astype(np.int32),
>>>
>>> np.squeeze(scores),
>>>
>>> category_index,
>>>
>>> use_normalized_coordinates=True,
>>>
>>> line_thickness=8,
>>>
>>> min_score_thresh=0.80)
>>>
>>>
>>> as well as this:
>>>
>>> textfile = open("json/"+filename_string+".json", "a")
>>>
>>> textfile.write(json.dumps(coordinates))
>>>
>>> textfile.write("\n")
>>>
>>>
>>> I think this should be all.
>>> Hi! This is not a issue.I add this simple loop to make the code detect
>>> all .JPG file the the testimg folder and export the .json file, img with
>>> boxes in json, json/testimg folder. Hope this can help someone who wants
>>> it.... P.S. i'm still a noob, so hope u can give me some advise
>>>
>>> 1.import some models:
>>>
>>> import glob
>>>
>>> import re
>>>
>>>
>>> 2.markdown default IMAGE PATH:
>>> "# IMAGE_NAME ="
>>> "# PATH_TO_IMAGE = os.path.join(CWD_PATH,IMAGE_NAME)"
>>>
>>> 3.And heres the change:
>>>
>>> for filename in sorted(glob.glob("testimg/"+ "*.JPG")):
>>>
>>> print("\n")
>>>
>>> print("Start parsing "+filename+"...")
>>>
>>> image = cv2.imread(filename)
>>>
>>> image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
>>>
>>> image_expanded = np.expand_dims(image_rgb, axis=0)
>>>
>>>
>>> filenameJ = re.sub(r".*?\/", "", filename)
>>>
>>> open("json/"+filenameJ+".json", "a").write(json.dumps(coordinates)+"\n"
>>>
>>>
>>>
>>> for coordinate in coordinates:
>>>
>>> (y1, y2, x1, x2, acc, classification) = coordinate
>>>
>>> height = y2-y1
>>>
>>> width = x2-x1
>>>
>>> crop = image[y1:y1+height, x1:x1+width]
>>>
>>> cv2.imwrite("json/"+filename, image)
>>>
>>> print(coordinate)
>>>
>>>
>>> —
>>> You are receiving this because you were mentioned.
>>> Reply to this email directly, view it on GitHub
>>> <#69 (comment)>,
>>> or unsubscribe
>>> <https://github.com/notifications/unsubscribe-auth/AOQW3D2SG7CMQSCAR3KNKH3R3U3BPANCNFSM4FFF37GQ>
>>> .
>>>
>>
|
i have same code for u to use me but class name is same for evertime ? |
Hello all Can anyone help me with this? I am adding the code in the right location in the visualization_utils file. |
how to deploy this model to productions in own server ??
plz help me
…On Sat, 5 Sep 2020 at 17:22, Raman Dutt ***@***.***> wrote:
Hello all
I added the piece of code suggested by @psi43 <https://github.com/psi43>
but I am getting this error.
*AttributeError: module 'object_detection.utils.visualization_utils' has
no attribute 'return_coordinates'*
Can anyone help me with this? I am adding the code in the right location
in the visualization_utils file.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOQW3DZFPYG6ZRXES65T7O3SEIRAPANCNFSM4FFF37GQ>
.
|
I ran the OpenPose on Colab and also got JSON files of the video which contains the key points however I'm confused as to how to use these JSON files in order to calculate rep counts and other pose evaluation techniques. Please help me out ! this is my code link: https://colab.research.google.com/drive/1tl0NvOSGLzP0vEpKLjlYEHVtEuJs77it?usp=sharing |
add this, it will solve ur problem.
|
it is not not working could you please share the latest code . |
did u add this to your utils/visualization_utils.py?
|
Thanks .
…On Wed, Feb 24, 2021 at 6:01 PM vinilreddy36 ***@***.***> wrote:
coordinates = vis_util.return_coordinates(
it is not not working could you please share the latest code .
I am getting AttributeError: module
'object_detection.utils.visualization_utils' has no attribute
'return_coordinates'.
did u add this to your utils/visualization_utils.py?
def return_coordinates(
image,
boxes,
classes,
scores,
category_index,
instance_masks=None,
instance_boundaries=None,
keypoints=None,
use_normalized_coordinates=False,
max_boxes_to_draw=20,
min_score_thresh=.5,
agnostic_mode=False,
line_thickness=4,
groundtruth_box_visualization_color='black',
skip_scores=False,
skip_labels=False):
# Create a display string (and color) for every box location, group any boxes
# that correspond to the same location.
box_to_display_str_map = collections.defaultdict(list)
box_to_color_map = collections.defaultdict(str)
box_to_instance_masks_map = {}
box_to_instance_boundaries_map = {}
box_to_score_map = {}
box_to_keypoints_map = collections.defaultdict(list)
if not max_boxes_to_draw:
max_boxes_to_draw = boxes.shape[0]
for i in range(min(max_boxes_to_draw, boxes.shape[0])):
if scores is None or scores[i] > min_score_thresh:
box = tuple(boxes[i].tolist())
if instance_masks is not None:
box_to_instance_masks_map[box] = instance_masks[i]
if instance_boundaries is not None:
box_to_instance_boundaries_map[box] = instance_boundaries[i]
if keypoints is not None:
box_to_keypoints_map[box].extend(keypoints[i])
if scores is None:
box_to_color_map[box] = groundtruth_box_visualization_color
else:
display_str = ''
if not skip_labels:
if not agnostic_mode:
if classes[i] in category_index.keys():
class_name = category_index[classes[i]]['name']
else:
class_name = 'N/A'
display_str = str(class_name)
if not skip_scores:
if not display_str:
display_str = '{}%'.format(int(100*scores[i]))
else:
display_str = '{}: {}%'.format(display_str, int(100*scores[i]))
box_to_display_str_map[box].append(display_str)
box_to_score_map[box] = scores[i]
if agnostic_mode:
box_to_color_map[box] = 'DarkOrange'
else:
box_to_color_map[box] = STANDARD_COLORS[
classes[i] % len(STANDARD_COLORS)]
# Draw all boxes onto image.
coordinates_list = []
counter_for = 0
for box, color in box_to_color_map.items():
ymin, xmin, ymax, xmax = box
height, width, channels = image.shape
ymin = int(ymin*height)
ymax = int(ymax*height)
xmin = int(xmin*width)
xmax = int(xmax*width)
if classes[counter_for] in category_index.keys():
class_name = category_index[classes[counter_for]]['name']
else:
class_name = 'N/A'
coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100), str(class_name)])
counter_for = counter_for + 1
return coordinates_list
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN5IJSPCOCXVGEWG4NUOGVLTATWR5ANCNFSM4FFF37GQ>
.
|
Could you please help me to creat an Flask application for custom object
detection model .
On Wed, Feb 24, 2021 at 11:55 PM Souravs Subudhi <unrivalledsaurav@gmail.com>
wrote:
… Thanks .
On Wed, Feb 24, 2021 at 6:01 PM vinilreddy36 ***@***.***>
wrote:
> coordinates = vis_util.return_coordinates(
>
> it is not not working could you please share the latest code .
> I am getting AttributeError: module
> 'object_detection.utils.visualization_utils' has no attribute
> 'return_coordinates'.
>
> did u add this to your utils/visualization_utils.py?
>
> def return_coordinates(
> image,
> boxes,
> classes,
> scores,
> category_index,
> instance_masks=None,
> instance_boundaries=None,
> keypoints=None,
> use_normalized_coordinates=False,
> max_boxes_to_draw=20,
> min_score_thresh=.5,
> agnostic_mode=False,
> line_thickness=4,
> groundtruth_box_visualization_color='black',
> skip_scores=False,
> skip_labels=False):
> # Create a display string (and color) for every box location, group any boxes
> # that correspond to the same location.
> box_to_display_str_map = collections.defaultdict(list)
> box_to_color_map = collections.defaultdict(str)
> box_to_instance_masks_map = {}
> box_to_instance_boundaries_map = {}
> box_to_score_map = {}
> box_to_keypoints_map = collections.defaultdict(list)
> if not max_boxes_to_draw:
> max_boxes_to_draw = boxes.shape[0]
> for i in range(min(max_boxes_to_draw, boxes.shape[0])):
> if scores is None or scores[i] > min_score_thresh:
> box = tuple(boxes[i].tolist())
> if instance_masks is not None:
> box_to_instance_masks_map[box] = instance_masks[i]
> if instance_boundaries is not None:
> box_to_instance_boundaries_map[box] = instance_boundaries[i]
> if keypoints is not None:
> box_to_keypoints_map[box].extend(keypoints[i])
> if scores is None:
> box_to_color_map[box] = groundtruth_box_visualization_color
> else:
> display_str = ''
> if not skip_labels:
> if not agnostic_mode:
> if classes[i] in category_index.keys():
> class_name = category_index[classes[i]]['name']
> else:
> class_name = 'N/A'
> display_str = str(class_name)
> if not skip_scores:
> if not display_str:
> display_str = '{}%'.format(int(100*scores[i]))
> else:
> display_str = '{}: {}%'.format(display_str, int(100*scores[i]))
> box_to_display_str_map[box].append(display_str)
> box_to_score_map[box] = scores[i]
> if agnostic_mode:
> box_to_color_map[box] = 'DarkOrange'
> else:
> box_to_color_map[box] = STANDARD_COLORS[
> classes[i] % len(STANDARD_COLORS)]
>
> # Draw all boxes onto image.
> coordinates_list = []
> counter_for = 0
> for box, color in box_to_color_map.items():
> ymin, xmin, ymax, xmax = box
> height, width, channels = image.shape
> ymin = int(ymin*height)
> ymax = int(ymax*height)
> xmin = int(xmin*width)
> xmax = int(xmax*width)
> if classes[counter_for] in category_index.keys():
> class_name = category_index[classes[counter_for]]['name']
> else:
> class_name = 'N/A'
> coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100), str(class_name)])
> counter_for = counter_for + 1
> return coordinates_list
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#69 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AN5IJSPCOCXVGEWG4NUOGVLTATWR5ANCNFSM4FFF37GQ>
> .
>
|
Thanks!
Really thanks for your support .
…On Mon, Mar 1, 2021 at 12:16 PM Ayushman Tyagi ***@***.***> wrote:
I could not use return-coordinates method because of Attribute error, so i
used the return_coordinates method inside the
visualize_boxes_and_labels_on_image_array() and made it return the
coordinates instead of image.
def visualize_boxes_and_labels_on_image_array(
image,
boxes,
classes,
scores,
category_index,
instance_masks=None,
instance_boundaries=None,
keypoints=None,
keypoint_scores=None,
keypoint_edges=None,
track_ids=None,
use_normalized_coordinates=False,
max_boxes_to_draw=20,
min_score_thresh=.5,
agnostic_mode=False,
line_thickness=4,
mask_alpha=.4,
groundtruth_box_visualization_color='black',
skip_boxes=False,
skip_scores=False,
skip_labels=False,
skip_track_ids=False):
"""Overlay labeled boxes on an image with formatted scores and label names.
This function groups boxes that correspond to the same location
and creates a display string for each detection and overlays these
on the image. Note that this function modifies the image in place, and
returns
that same image.
Args:
image: uint8 numpy array with shape (img_height, img_width, 3)
boxes: a numpy array of shape [N, 4]
classes: a numpy array of shape [N]. Note that class indices are 1-based,
and match the keys in the label map.
scores: a numpy array of shape [N] or None. If scores=None, then
this function assumes that the boxes to be plotted are groundtruth
boxes and plot all boxes as black with no classes or scores.
category_index: a dict containing category dictionaries (each holding
category index id and category name name) keyed by category indices.
instance_masks: a uint8 numpy array of shape [N, image_height,
image_width],
can be None.
instance_boundaries: a numpy array of shape [N, image_height, image_width]
with values ranging between 0 and 1, can be None.
keypoints: a numpy array of shape [N, num_keypoints, 2], can
be None.
keypoint_scores: a numpy array of shape [N, num_keypoints], can be None.
keypoint_edges: A list of tuples with keypoint indices that specify which
keypoints should be connected by an edge, e.g. [(0, 1), (2, 4)] draws
edges from keypoint 0 to 1 and from keypoint 2 to 4.
track_ids: a numpy array of shape [N] with unique track ids. If provided,
color-coding of boxes will be determined by these ids, and not the class
indices.
use_normalized_coordinates: whether boxes is to be interpreted as
normalized coordinates or not.
max_boxes_to_draw: maximum number of boxes to visualize. If None, draw
all boxes.
min_score_thresh: minimum score threshold for a box or keypoint to be
visualized.
agnostic_mode: boolean (default: False) controlling whether to evaluate in
class-agnostic mode or not. This mode will display scores but ignore
classes.
line_thickness: integer (default: 4) controlling line width of the boxes.
mask_alpha: transparency value between 0 and 1 (default: 0.4).
groundtruth_box_visualization_color: box color for visualizing groundtruth
boxes
skip_boxes: whether to skip the drawing of bounding boxes.
skip_scores: whether to skip score when drawing a single detection
skip_labels: whether to skip label when drawing a single detection
skip_track_ids: whether to skip track id when drawing a single detection
Returns:
uint8 numpy array with shape (img_height, img_width, 3) with overlaid
boxes.
"""
Create a display string (and color) for every box location, group any boxes that
correspond to the same location.
box_to_display_str_map = collections.defaultdict(list)
box_to_color_map = collections.defaultdict(str)
box_to_instance_masks_map = {}
box_to_instance_boundaries_map = {}
box_to_keypoints_map = collections.defaultdict(list)
box_to_keypoint_scores_map = collections.defaultdict(list)
box_to_track_ids_map = {}
if not max_boxes_to_draw:
max_boxes_to_draw = boxes.shape[0]
for i in range(boxes.shape[0]):
if max_boxes_to_draw == len(box_to_color_map):
break
if scores is None or scores[i] > min_score_thresh:
box = tuple(boxes[i].tolist())
if instance_masks is not None:
box_to_instance_masks_map[box] = instance_masks[i]
if instance_boundaries is not None:
box_to_instance_boundaries_map[box] = instance_boundaries[i]
if keypoints is not None:
box_to_keypoints_map[box].extend(keypoints[i])
if keypoint_scores is not None:
box_to_keypoint_scores_map[box].extend(keypoint_scores[i])
if track_ids is not None:
box_to_track_ids_map[box] = track_ids[i]
if scores is None:
box_to_color_map[box] = groundtruth_box_visualization_color
else:
display_str = ''
if not skip_labels:
if not agnostic_mode:
if classes[i] in six.viewkeys(category_index):
class_name = category_index[classes[i]]['name']
else:
class_name = 'N/A'
display_str = str(class_name)
if not skip_scores:
if not display_str:
display_str = '{}%'.format(round(100
*scores[i])) else: display_str = '{}: {}%'.format(display_str, round(100*
scores[i]))
if not skip_track_ids and track_ids is not None:
if not display_str:
display_str = 'ID {}'.format(track_ids[i])
else:
display_str = '{}: ID {}'.format(display_str, track_ids[i])
box_to_display_str_map[box].append(display_str)
if agnostic_mode:
box_to_color_map[box] = 'DarkOrange'
elif track_ids is not None:
prime_multipler = _get_multiplier_for_color_randomness()
box_to_color_map[box] = STANDARD_COLORS[
(prime_multipler * track_ids[i]) % len(STANDARD_COLORS)]
else:
box_to_color_map[box] = STANDARD_COLORS[
classes[i] % len(STANDARD_COLORS)]
Draw all boxes onto image.
for box, color in box_to_color_map.items():
ymin, xmin, ymax, xmax = box
if instance_masks is not None:
draw_mask_on_image_array(
image,
box_to_instance_masks_map[box],
color=color,
alpha=mask_alpha
)
if instance_boundaries is not None:
draw_mask_on_image_array(
image,
box_to_instance_boundaries_map[box],
color='red',
alpha=1.0
)
draw_bounding_box_on_image_array(
image,
ymin,
xmin,
ymax,
xmax,
color=color,
thickness=0 if skip_boxes else line_thickness,
display_str_list=box_to_display_str_map[box],
use_normalized_coordinates=use_normalized_coordinates)
if keypoints is not None:
keypoint_scores_for_box = None
if box_to_keypoint_scores_map:
keypoint_scores_for_box = box_to_keypoint_scores_map[box]
draw_keypoints_on_image_array(
image,
box_to_keypoints_map[box],
keypoint_scores_for_box,
min_score_thresh=min_score_thresh,
color=color,
radius=line_thickness / 2,
use_normalized_coordinates=use_normalized_coordinates,
keypoint_edges=keypoint_edges,
keypoint_edge_color=color,
keypoint_edge_width=line_thickness // 2)
coordinates =return_coordinates(image, boxes, classes, scores,
category_index,use_normalized_coordinates=True,
line_thickness=8,
min_score_thresh=0.80)
return coordinates
** But when i run this method, it returns a ndarray type obejct.
[[[255 255 255]
[255 255 255]
[255 255 255]
...
[255 255 255]
[255 255 255]
[255 255 255]]
[[255 255 255]
[255 255 255]
[255 255 255]
...
[255 255 255]
[255 255 255]
[255 255 255]]
[[255 255 255]
[255 255 255]
[255 255 255]
...
[255 255 255]
[255 255 255]
[255 255 255]]
...
[[250 254 255]
[248 252 251]
[229 235 225]
...
[255 255 255]
[255 255 255]
[255 255 255]]
[[234 236 235]
[249 250 254]
[254 255 255]
...
[246 246 246]
[241 241 241]
[255 255 255]]
[[254 255 246]
[232 234 231]
[251 251 255]
...
[255 255 255]
[255 255 255]
[255 255 255]]]
***and i get another error when i am trying to write the output to a file
json/test.json
File "C:\Users\aytya\anaconda3\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.*class*.*name*} '
TypeError: Object of type ndarray is not JSON serializable
In my project i want to detect object which has 2 classes i.e red box and
blue box and i want their coordinates in the image. Please help me find
these coordinates _/_
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN5IJSJQCXMC5CWD6BZJQ23TBMZ35ANCNFSM4FFF37GQ>
.
|
I read this thread and it's quite interesting to crop bounding boxes after training of tensorflow object detection API. |
hiii...friends ..I am working on a project(computer vision-video tracking-multi objects) i need help with how I can put unique id and fixed for each object in frames I know detected contours and draw box rectangles for each object but I cannot fix id for each one. |
@Mehran970 🙏🙏🙏 Thanks a lot. It worked for multiple objects in a frame. |
EDIT: Nevermind, got it to work!
Hey, first off, great tutorial, thank you so much.
I got it to run on ubuntu 16.04 as well with ease but I have a problem. I'm running on a CLI Ubuntu server, so instead of using an image as output, I'd just like to have the coordinates of the boxes.
I looked into the Object_detection_image.py and found where the boxes are being drawn, but it uses a function named visualize_boxes_and_labels_on_image_array to draw them.
If I try to ouput the np.squeeze(boxes), it returns this:
Is there a way to just get the coordinates from that?
Thank you for your time!
EDIT:
Okay, I added a new function to the visualization_utils.py that returns the "ymin, ymax, xmin, xmax" variables, used in other functions of that file to draw the boxes.
The problem is, they look like this:
[[0.5897822976112366, 0.8703674674034119, 0.35585764050483704, 0.5124077796936035], [0.6508234739303589, 0.8575793504714966, 0.13419045507907867, 0.2114586979150772]]
I was expecting coordinates. These seem like percentages.
EDIT:
Okay, I got it to work.
The text was updated successfully, but these errors were encountered: