EdjeElectronics / TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10

How to train a TensorFlow Object Detection Classifier for multiple object detection on Windows
Apache License 2.0
2.92k stars 1.3k forks source link

Extracting coordinates instead of drawing a box #69

Open psi43 opened 6 years ago

psi43 commented 6 years ago

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:

[[0.5897823  0.35585764 0.87036747 0.5124078 ]
 [0.6508235  0.13419046 0.85757935 0.2114587 ]
 [0.64070517 0.14992228 0.8580698  0.23488007]
 ...
 [0.         0.         0.         0.        ]
 [0.         0.         0.         0.        ]
 [0.         0.         0.         0.        ]]

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.

hiteshreddy95 commented 4 years ago

Hey @ManafMukred , previously i was using image as my input for object detection. I am able to extract the coordinates. But when i try to evaluate with the ground truth, i am getting very bad result. I would like to know more about the evaluation part for multiple images in a single frame.

hiteshreddy95 commented 4 years ago

@ManafMukred if you don't mind, can you please share me your email id? so that i can talk to you through hangout and maybe you can understand my problem.

ManafMukred commented 4 years ago

I'm not that expert .. just trying to help ... better post here so others can help too :) @hiteshreddy95 even if it was long .. just put it all here

Firdanis commented 4 years ago

@hiteshreddy95 Good evening, I was able to redo the code so that it runs on video and from a webcam. He also recorded the detected object .xml file with a picture, so that later it could be opened through labelImg. Sorry for my bad English. Mail to contact me: ganievf@mail.ru I will help with the code, but I will not upload it to the public.

wanghetongtt commented 4 years ago

@psi43 great work! one question, for some reason, my number of coordinate got from your code is not the same as my predictions. in the output picture i got 7 predictions but when i print (coordinate) i only got 4 WeChat Image_20200102213014 WeChat Image_20200102212845

psi43 commented 4 years ago

@psi43 great work! one question, for some reason, my number of coordinate got from your code is not the same as my predictions. in the output picture i got 7 predictions but when i print (coordinate) i only got 4 WeChat Image_20200102213014 WeChat Image_20200102212845

I'm not 100% sure, but I believe that I ran into the same problem ages ago and it had something to do with tweaking sensitivity. You can set it up in a way that it omits anything with an accuracy of below x% and I think that it's set to 65% by default.

adifdwimaulana commented 4 years ago

@psi43 great work! one question, for some reason, my number of coordinate got from your code is not the same as my predictions. in the output picture i got 7 predictions but when i print (coordinate) i only got 4 WeChat Image_20200102213014 WeChat Image_20200102212845

I'm not 100% sure, but I believe that I ran into the same problem ages ago and it had something to do with tweaking sensitivity. You can set it up in a way that it omits anything with an accuracy of below x% and I think that it's set to 65% by default.

Can I see your code ? Because I've spent a week to solve this problem. I can only show the coordinate in numpy array not in pixel like your own

psi43 commented 4 years ago

I just solved the issue ... looks like the label is not updated in the for loop .. so if there are multiple labels in the same frame, it will return the latest one only ... I've edited the last few lines in vis_util.return_coordinates function to be like this:

# 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),display_strs[counter_for]])
    counter_for = counter_for + 1

  return coordinates_list 

@ManafMukred Hey, I just ran into the same issue, where every object gets labeled as the same thing. I tried your code but was confused as to what the variable display_strs was. I found out that you can just use box_to_display_str_map[box][0] instead of display_strs[counter_for]. That way you don't have to aggregate the labels in a new variable, since box_to_display_str_map[box] is already being filled in the process.

ramana1dev commented 4 years ago

@psi43 please help!!!!

whatever image is given ,20 random coordinates are outputted as below: [206, 236, 972, 1001, 100, 'N/A: 100%'] [285, 312, 907, 931, 100, 'N/A: 100%'] [317, 347, 877, 903, 100, 'N/A: 100%'] [338, 367, 898, 924, 100, 'N/A: 100%'] [285, 316, 910, 937, 100, 'N/A: 100%'] [320, 355, 881, 907, 100, 'N/A: 100%'] [196, 243, 975, 1005, 100, 'N/A: 100%'] [293, 319, 901, 927, 100, 'N/A: 100%'] [317, 347, 884, 910, 100, 'N/A: 100%'] [328, 359, 886, 911, 100, 'N/A: 100%'] [341, 371, 903, 929, 100, 'N/A: 100%'] [312, 342, 870, 900, 100, 'N/A: 100%'] [333, 361, 902, 930, 100, 'N/A: 100%'] [337, 369, 889, 919, 100, 'N/A: 100%'] [304, 337, 894, 922, 100, 'N/A: 100%'] [194, 228, 967, 999, 100, 'N/A: 100%'] [292, 320, 888, 918, 100, 'N/A: 100%'] [300, 328, 906, 932, 100, 'N/A: 100%'] [330, 363, 880, 907, 100, 'N/A: 100%'] [322, 351, 903, 930, 100, 'N/A: 100%']

irrespective of number of detections.

--> visualization_utils.py: coordinates_list = [] counter_for = 0 for box, color in box_to_color_map.items(): ymin, xmin, ymax, xmax = box image = np.asarray(image) height, width, channels = image.shape ymin = int(yminheight) ymax = int(ymaxheight) xmin = int(xminwidth) xmax = int(xmaxwidth) coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100), box_to_display_str_map[box][0]]) counter_for = counter_for + 1

return coordinates_list

--> Detect.py

label_map = label_map_util.load_labelmap(PATH_TO_LABELS) categories = label_map_util.convert_label_map_to_categories(label_map , max_num_classes=2, use_display_name=True) category_index = label_map_util.create_category_index(categories) coordinates = vis_utils.return_coordinates( img, 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.85)

textfile = open("json/jsondata.json", "a")

  #textfile.write(json.dumps(coordinates))
  #textfile.write("\n")
  for coordinate in coordinates:
        print(coordinate)
        (y1, y2, x1, x2, acc, claa) = coordinate
alainkaiser commented 4 years ago

@ramana1dev Have you tried the solution from @ajsalkp commented on 18 Nov 2019? Worked perfectly for our use-case 👍

ramana1dev commented 4 years ago

@ramana1dev Have you tried the solution from @ajsalkp commented on 18 Nov 2019? Worked perfectly for our use-case 👍

used his snippet only...but the weird part is whatever the number of detections are , but it is returning 20 coordinates...and 'N/A' as class and 100 as score...

anzy0621 commented 4 years ago

Hi all, I had a question. My detections file has the output of only the frames that have detections and it does not write the frame numbers which has no detections at all. example: if frame 1,2,3,4 do not have nay detections it is not printed in the text file... is there a way to print those frames too?

Thank you in advance! Any input is appreciated!

adifdwimaulana commented 4 years ago

Hi all, I had a question. My detections file has the output of only the frames that have detections and it does not write the frame numbers which has no detections at all. example: if frame 1,2,3,4 do not have nay detections it is not printed in the text file... is there a way to print those frames too?

Thank you in advance! Any input is appreciated!

Can you show us your code ? So, we can figure what is the problem

ManafMukred commented 4 years ago

Hi all, I had a question. My detections file has the output of only the frames that have detections and it does not write the frame numbers which has no detections at all. example: if frame 1,2,3,4 do not have nay detections it is not printed in the text file... is there a way to print those frames too?

Thank you in advance! Any input is appreciated!

you should snap your code in that section of showing the frame .. I'd guess you are writing the imshow command in the detection loop while it should be outside of it

Mehran970 commented 4 years ago

You do not need to add any additional programs (return_coordinates) to determine the objects coordinates. just use dnn.NMSBoxes command in opencv as follow:


# This code return objects coordination in a variable as matrix (signs) and their labels (labels):

idxs = cv2.dnn.NMSBoxes(boxes, scores, 0.5, 1.5)

# define a array as matrix
signs = []
labels = []
for i in range(len(idxs)):
        signs.append(i)
        labels.append(i)

# ensure at least one detection exists
if len(idxs) > 0:
    # loop over the indexes we are keeping
    for i in idxs.flatten():
        # extract the bounding box coordinates
        ymin = int((boxes[0][i][0] * height))
        xmin = int((boxes[0][i][1] * width))
        ymax = int((boxes[0][i][2] * height))
        xmax = int((boxes[0][i][3] * width))
        signs[i] = [ymin,ymax,xmin,xmax]
        labels[i] = int(classes[0][i])

print(signs)
print(labels)
My-Lo commented 4 years ago

Hi everyone, I have some problems, basically i am making a project for smart refrigerator where i use object detection to know what's inside the fridge, i use two classes for a start, bottle and can, I use 1 bottle and 1 can as sample, thankfully it can classify bottle and can in the frame/image but my prob is that for the code below:

coordinates_list.append([ymin, ymax, xmin, xmax, (box_to_score_map[box]*100), str(class_name)

for the class name when it show this:

[358, 705, 990, 1256, 99.93228912353516, 'Bottle'] [341, 708, 284, 469, 99.69232678413391, 'Bottle']

I think it overwrite the class for can, if i remove the bottle out from the frame/image, then only the 'Can' shows at the class_name

I attached an image for the bottle and can detection Thank you in advance result

morningcloud commented 4 years ago

Where can i find object_detection_dir.py file?

I am having the same question, I can't find the object_detection_dir.py file @psi43 appreciate if you can help

psi43 commented 4 years ago

Where can i find object_detection_dir.py file?

I am having the same question, I can't find the object_detection_dir.py file @psi43 appreciate if you can help

It's a file that I made. Basically just a copy of object_detection.py but with inotify, watching a directory and automatically evaluating every file being put into it.

Just paste the code snippet I posted into the object_detection.py.

morningcloud commented 4 years ago

Where can i find object_detection_dir.py file?

I am having the same question, I can't find the object_detection_dir.py file @psi43 appreciate if you can help

It's a file that I made. Basically just a copy of object_detection.py but with inotify, watching a directory and automatically evaluating every file being put into it.

Just paste the code snippet I posted into the object_detection.py.

Thanks for the clarification

Duderinooo commented 4 years ago

@psi43 Hello, thanks for the Thread was very helpfull to me. I am new to python and I dont really understand how to crop all the images inside a directory with the help of a for loop inside the Object_detection_images.py If you could clarify that part a bit would be very helpful to me.

psi43 commented 4 years ago

@psi43 Hello, thanks for the Thread was very helpfull to me. I am new to python and I dont really understand how to crop all the images inside a directory with the help of a for loop inside the Object_detection_images.py If you could clarify that part a bit would be very helpful to me.

Depends on what exactly you want. If you just want to go through all existing files in a directory:

    path = "path/to/dir/"
    for file in os.scandir(path):
        tail, head = os.path.split(file.path)
        filename, extension = os.path.splitext(head)
        print(tail + "/" + filename + extension)
        evaluate_image(path, filename)

If you want to monitor a directory for new files being put into it:

import inotify.adapters
i = inotify.adapters.Inotify()

to_evaluate_path = "dir/to/evaluate"
to_evaluate = os.listdir(to_evaluate_path)

i.add_watch(to_evaluate_path)

for event in i.event_gen(yield_nones=False):
    (_, type_names, path, filename) = event
    if "IN_CLOSE_WRITE" in type_names:
        evaluate_image(path, filename)

I hope both snippets work, I didn't have time to test them. I copied them out of my current project.

yurixasp commented 4 years ago

Hello @psi43 , help me please.. Can i export the coordinates in each of photo which i get to .xml file ? i want to testing all photos (ex: 100 photos) and export all coordinate to .xml file (so have 100 xml) in every photo

Duderinooo commented 4 years ago

Hey @psi43 Thanks for your previous help! Cropping dirs works like a charm now. This might be redundant but I would like to ask if you have any idea on how to delete images which dont reach a minimum label score threshold?

ruzgarkanar commented 4 years ago

hi guys. HELP! How do I measure the distance between the objects I detected on the webcam?

Mehran970 commented 4 years ago

hi Ruzzg. Install scipy (pip install scipy) and import distance as below:

from scipy.spatial import distance as dist

and next use this code:

D = dist.euclidean((xA, yA), (xB, yB))

for more detail go to here

ruzgarkanar commented 4 years ago

hi Ruzzg. Install scipy (pip install scipy) and import distance as below:

from scipy.spatial import distance as dist

and next use this code:

D = dist.euclidean((xA, yA), (xB, yB))

for more detail go to here

my problem was actually, measure distance between real-time objects. but I think it will not work properly because it is 2D. Depth is important in this case.You can give me an idea on this. What should I do to be able to determine the distances correctly. this way I found the midpoint but won't find the right spot from different angles.

for i in range(len(idx)): signs.append(i) labels.append(i) if len(idx) > 0: for i in idx.flatten(): height, width, channels = image.shape ymin = int((boxes[0][i][0] height)) xmin = int((boxes[0][i][1] width)) ymax = int((boxes[0][i][2] height)) xmax = int((boxes[0][i][3] width)) mid_x = (xmin + xmax)/2 mid_y = (ymin + ymax)/2 cv2.circle(image, (int(mid_x), int(mid_y)), 5, (255, 255, 255), -1) cv2.putText(image, "centroid", (int(mid_x) - 25, int(mid_y) - 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)

Mehran970 commented 4 years ago

Each movie frame is actually a two-dimensional image. So you can't find the distance between two objects in depth. Your solution is to install multiple cameras at different angles, which can be used to measure the distance between objects in three-dimensions. The more cameras you have, the more accurate you will be.

ruzgarkanar commented 4 years ago

https://github.com/KleinYuan/tf-3d-object-detection İ think 3D models are trained and used here. Can I determine the 3D model by training and using it? and can you explain to me how to train and use the model I want in tensorflow? I couldn't understand because my English is not very good :)

Sanket-15 commented 4 years ago

@psi43 Hello, I'm trying to add your code to utils/visualization_utils.py file.

While running the code I'm facing the following error:

Traceback (most recent call last): File "Object_detection_dir.py", line 112, in coordinates = vis_util.return_coordinates( AttributeError: module 'object_detection.utils.visualization_utils' has no attribute 'return_coordinates'

Please help me out.

vinsonlau commented 4 years ago

Hello, The coordinates will be retrieved every frames, but some frames do not have the object that is being detected and so the boxes will not be drawn. May I know is there any variable that I can use to capture whether a box is drawn or not? The reason is I want to display its height if an object is detected and do not write anything if nothing is detected.

Thanks in advance!

Sn0wl3r0ker commented 4 years ago

@psi43 Hello, I'm trying to add your code to utils/visualization_utils.py file.

While running the code I'm facing the following error:

Traceback (most recent call last): File "Object_detection_dir.py", line 112, in coordinates = vis_util.return_coordinates( AttributeError: module 'object_detection.utils.visualization_utils' has no attribute 'return_coordinates'

Please help me out.

Try to use this command. export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim P.S. pwd is the command that u should type in terminal;change it into 'pwd'.

jix1710 commented 4 years ago

@psi43 great work! one question, for some reason, my number of coordinate got from your code is not the same as my predictions. in the output picture i got 7 predictions but when i print (coordinate) i only got 4 WeChat Image_20200102213014 WeChat Image_20200102212845

hii bro how yo label name for coodinate ?? and mor then 6 label to how find coodinate in one image?

psi43 commented 4 years ago

@psi43 Hello, I'm trying to add your code to utils/visualization_utils.py file.

While running the code I'm facing the following error:

Traceback (most recent call last): File "Object_detection_dir.py", line 112, in coordinates = vis_util.return_coordinates( AttributeError: module 'object_detection.utils.visualization_utils' has no attribute 'return_coordinates'

Please help me out.

Check out the 4th post in this thread. Copy the function called return_coordinates and add it to your visualization_utils.

Sorry for not being able to answer all questions asked here. I believe I've posted this before, but my version of this object detection project is vastly different from the original now, and has been for a long time. So trying to remember/find out what exactly I did to solve some of the problems other people also ran into is quite time consuming.

jix1710 commented 4 years ago

@psi43 Hello, I'm trying to add your code to utils/visualization_utils.py file. While running the code I'm facing the following error: Traceback (most recent call last): File "Object_detection_dir.py", line 112, in coordinates = vis_util.return_coordinates( AttributeError: module 'object_detection.utils.visualization_utils' has no attribute 'return_coordinates' Please help me out.

Check out the 4th post in this thread. Copy the function called return_coordinates and add it to your visualization_utils.

Sorry for not being able to answer all questions asked here. I believe I've posted this before, but my version of this object detection project is vastly different from the original now, and has been for a long time. So trying to remember/find out what exactly I did to solve some of the problems other people also ran into is quite time consuming.

thank you bro

jix1710 commented 4 years ago

@psi43 Hello, I'm trying to add your code to utils/visualization_utils.py file. While running the code I'm facing the following error: Traceback (most recent call last): File "Object_detection_dir.py", line 112, in coordinates = vis_util.return_coordinates( AttributeError: module 'object_detection.utils.visualization_utils' has no attribute 'return_coordinates' Please help me out.

Check out the 4th post in this thread. Copy the function called return_coordinates and add it to your visualization_utils.

Sorry for not being able to answer all questions asked here. I believe I've posted this before, but my version of this object detection project is vastly different from the original now, and has been for a long time. So trying to remember/find out what exactly I did to solve some of the problems other people also ran into is quite time consuming.

i solve the problem

jix1710 commented 4 years ago

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.

how to find centerlpoint in this code ?? box center point for xmin ymin xmax ymax?

sorry bro for disturb to you ..but sove this problemm for me.. thxx

psi43 commented 4 years ago

@jix1710 You could do the following: x middle point = xmax - (xmax-xmin)/2 y middle point = ymax - (ymax-ymin)/2

jix1710 commented 4 years ago

@jix1710 You could do the following: x middle point = xmax - (xmax-xmin)/2 y middle point = ymax - (ymax-ymin)/2

bro i have to find middle point for 1 label "A" in image and 2 label "a"to find middle point but how is possible to connect two middle point in side line to connect?

jix1710 commented 4 years ago

thx bro but i have some problems i complete this project but have the same add to this program .. how to possible to middle point compared to image and draw line in middle point

On Fri, 12 Jun 2020 at 16:39, psi43 notifications@github.com wrote:

@jix1710 https://github.com/jix1710 You could do the following: x middle point = xmax - (xmax-xmin)/2 y middle point = ymax - (ymax-ymin)/2

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/issues/69#issuecomment-643214626, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOQW3D5SS7JEUR6AR34Z7ATRWIEIBANCNFSM4FFF37GQ .

ruzgarkanar commented 4 years ago

On the test set I want to see the mAP score and which pictures I know correctly. But I failed Is there anyone who can help with this? https://github.com/tensorflow/models/issues/4778#issuecomment-430262110 I followed here but it didn't. I am using Tensorflow 1.14. Actually, I want to move to 2.2, but there are constant problems. Could it be about the version?

psi43 commented 4 years ago

@Ruzzg I've tried to upgrade from TF 1.14 to 2.x multiple times now and never managed to pull it off. There are always so many things that stop working, so if you ever figure out how to do it, please let us know.

ruzgarkanar commented 4 years ago

@psi43 Did you get the mAP metric at 1.14? And I have one more question. When I run the model I trained, it placed some objects in a rectangle 2 times. For example, both the top of the dining table is rectangular and the whole is covered, what could be the reason? Is it due to labeling or data?

psi43 commented 4 years ago

@Ruzzg Possibly labeling. I had a similar problem, so I did away with it programmatically by discarding any box that was (fully or partially) drawn inside a bigger box. And no, I have not even tried to get the mAP metric at all.

ruzgarkanar commented 4 years ago

@psi43 In fact, it is necessary to see how much learning has been learned for the adequacy of the trained pictures or by adding pictures according to the situation.I think the mAP value seems very important in this regard. If you succeed, if you share it, I will be very happy here :)

jix1710 commented 4 years ago

hi sir how to make coordinates snd output data in excel sheet bs of i make regression in this output excel data

On Tue, 16 Jun 2020 at 13:56, psi43 notifications@github.com wrote:

@Ruzzg https://github.com/Ruzzg Possibly labeling. I had a similar problem, so I did away with it programmatically by discarding any box that was (fully or partially) drawn inside a bigger box. And no, I have not even tried to get the mAP metric at all.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/issues/69#issuecomment-644615642, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOQW3D5ZRXUDKDVPECOL7TDRW4UDNANCNFSM4FFF37GQ .

psi43 commented 4 years ago

@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.

jix1710 commented 4 years ago

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. """" textfile = open("json/"+filename_string+".json", "a") textfile.write(json.dumps(coordinates)) textfile.write("\n"""""")

how to thhis formet writine in csv (textfile) ???

jix1710 commented 4 years ago

I just solved the issue ... looks like the label is not updated in the for loop .. so if there are multiple labels in the same frame, it will return the latest one only ... I've edited the last few lines in vis_util.return_coordinates function to be like this:

# 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),display_strs[counter_for]])
    counter_for = counter_for + 1

  return coordinates_list 

[[483.25], [681.0], ['VO: 99%'], 'V'] [[427.75], [491.0], ['TO: 96%'], 'O'] how i find the label full name?? bc the not come VO is come to outpot only V ? wacth may output in last value?

jix1710 commented 4 years ago
              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 notifications@github.com 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 https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/issues/69#issuecomment-646485084, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOQW3D4Q35TSYBF5AJYHYJLRXMHVDANCNFSM4FFF37GQ .

jix1710 commented 4 years ago

i use your return coordinates code..

On Sun, 21 Jun 2020 at 11:50, jix italiya jlitaliya82@gmail.com 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 notifications@github.com 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 https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/issues/69#issuecomment-646485084, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOQW3D4Q35TSYBF5AJYHYJLRXMHVDANCNFSM4FFF37GQ .