You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys, can someone please help me with my thesis, I have labeled my images with LabelMe software. I have used 80 images for train and 20 for val. I train the model with no errors, but i get 0 accuracy when i test it afterwards. Can someone please give me any ideas how to fix this, or please if you have worked with LabelMe can you share the code with me, I would be very thankful. Thank you!
class CustomDataset(utils.Dataset):
def load_custom(self, dataset_dir, subset):
# Add the class
self.add_class("object", 1, "tooth")
# Make sure the subset is either 'train' or 'val'
assert subset in ["train", "val"]
dataset_dir = os.path.join(dataset_dir, subset)
# Iterate over all JSON files in the directory
for filename in os.listdir(dataset_dir):
if filename.endswith(".json"):
json_file = os.path.join(dataset_dir, filename)
# print(f"Processing {json_file}...") # Print the current JSON file being processed
annotations_json = json.load(open(json_file))
shapes = annotations_json.get('shapes', [])
print("shapes:", len(shapes))
# If there are no annotations in the file, skip it
if not shapes:
continue
# Extract image filename and load the image
image_filename = annotations_json['imagePath'].split('\\')[-1]
image_path = os.path.join(dataset_dir, image_filename)
# print(f"Loading image {image_path}...") # Print the image file being loaded
num_ids = [1] * len(shapes)
print("numids",num_ids)
image = skimage.io.imread(image_path)
height, width = image.shape[:2]
# Add the image to the dataset
self.add_image(
"object",
image_id=image_filename,
path=image_path,
width=width, height=height,
polygons=[{
'name': 'polygon',
'all_points_x': [point[0] for point in shape['points']],
'all_points_y': [point[1] for point in shape['points']]
} for shape in shapes],
num_ids=num_ids
)
def load_mask(self, image_id):
"""Generate instance masks for an image.
Returns:
masks: A bool array of shape [height, width, instance count] with
one mask per instance.
class_ids: a 1D array of class IDs of the instance masks.
"""
# If not an object dataset image, delegate to parent class.
image_info = self.image_info[image_id]
if image_info["source"] != "object":
return super(self.__class__, self).load_mask(image_id)
# Initialize the mask array
mask = np.zeros([image_info["height"], image_info["width"], len(image_info["polygons"])],
dtype=np.uint8)
for i, p in enumerate(image_info["polygons"]):
# Clipping the coordinates to ensure they are within the image dimensions
all_points_x = np.clip(p['all_points_x'], 0, image_info["width"] - 1)
all_points_y = np.clip(p['all_points_y'], 0, image_info["height"] - 1)
# Get indexes of pixels inside the polygon and set them to 1
rr, cc = skimage.draw.polygon(all_points_y, all_points_x)
mask[rr, cc, i] = 1
# Return mask, and array of class IDs of each instance. Since we have
# one class ID only, we return an array of 1s
return mask.astype(np.bool), np.ones([mask.shape[-1]], dtype=np.int32)
def image_reference(self, image_id):
"""Return the path of the image."""
info = self.image_info[image_id]
if info["source"] == "object":
return info["path"]
else:
super(self.__class__, self).image_reference(image_id)
The text was updated successfully, but these errors were encountered:
Hi guys, can someone please help me with my thesis, I have labeled my images with LabelMe software. I have used 80 images for train and 20 for val. I train the model with no errors, but i get 0 accuracy when i test it afterwards. Can someone please give me any ideas how to fix this, or please if you have worked with LabelMe can you share the code with me, I would be very thankful. Thank you!
class CustomDataset(utils.Dataset):
The text was updated successfully, but these errors were encountered: