Skip to content
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

Testing commit made by contributor #137

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions pylabel/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _GetValueOrBlank(element, user_input=None):


# These are the valid columns in the pylabel annotations table.
def ImportCoco(path, path_to_images=None, name=None, encoding='utf-8'):
def ImportCoco(path, path_to_images=None, name=None, encoding="utf-8"):
"""
This function takes the path to a JSON file in COCO format as input. It returns a PyLabel dataset object that contains the annotations.

Expand Down Expand Up @@ -146,7 +146,7 @@ def ImportCoco(path, path_to_images=None, name=None, encoding='utf-8'):
return dataset


def ImportVOC(path, path_to_images=None, name="dataset", encoding='utf-8'):
def ImportVOC(path, path_to_images=None, name="dataset", encoding="utf-8"):
"""
Provide the path a directory with annotations in VOC Pascal XML format and it returns a PyLabel dataset object that contains the annotations.

Expand Down Expand Up @@ -190,7 +190,7 @@ def GetCatId(cat_name):
xml_data = open(filepath, "r", encoding=encoding).read() # Read file
root = ET.XML(xml_data) # Parse XML
# ignore "folder" node in xml
#folder = _GetValueOrBlank(root.find("folder"), user_input=path_to_images)
# folder = _GetValueOrBlank(root.find("folder"), user_input=path_to_images)
folder = path_to_images if path_to_images else "."
# "filename" node in xml sometimes is invalid
# only get suffix
Expand All @@ -205,7 +205,7 @@ def GetCatId(cat_name):
row = {}
# Build dictionary that will be become the row in the dataframe
row["img_folder"] = folder
row["img_filename"] = filename.name.replace(".xml",suffix)
row["img_filename"] = filename.name.replace(".xml", suffix)
row["img_id"] = img_id
row["img_width"] = size_width
row["img_height"] = size_height
Expand Down Expand Up @@ -266,7 +266,7 @@ def ImportYoloV5(
cat_names=[],
path_to_images="",
name="dataset",
encoding='utf-8',
encoding="utf-8",
):
"""
Provide the path a directory with annotations in YOLO format and it returns a PyLabel dataset object that contains the annotations.
Expand Down Expand Up @@ -348,8 +348,13 @@ def GetCatNameFromId(cat_id, cat_names):

im = cv2.imdecode(numpyarray, cv2.IMREAD_UNCHANGED)

#im = cv2.imread(str(image_path))
img_height, img_width, img_depth = im.shape
img_height = im.shape[0]
img_width = im.shape[1]
# If the image is grayscale then there is no img_depth
if len(im.shape) == 2:
img_depth = 1
else:
img_depth = im.shape[2] # 3 for color images

row["img_id"] = img_id
row["img_width"] = img_width
Expand Down Expand Up @@ -514,7 +519,7 @@ def ImportYoloV5WithYaml(
image_ext="jpg",
name_of_annotations_folder="labels",
path_to_annotations=None,
encoding='utf-8',
encoding="utf-8",
):
"""Import a YOLO dataset by reading the YAML file to extract the class names, image and label locations,
and preserve if an image should be in the train, test, or val split.
Expand Down
Loading