Open anushree9699 opened 3 months ago
@anushree9699
Even though if you are keeping it 0, 1, 2 and 3 as pixel values and still if there is a problem i think while doing some image processing it would have got confused as the pixel range is very near. You can keep 0, 80, 170, 255 for the train masks of 4 different classes and train. Let me know if u r facing any issues even after this type of change
Then dont change the class keep it as 4
I used the pillow, this was the function i used to parse each image:
def parse_jpeg_image(image_path):
try:
with Image.open(image_path) as img:
width, height = img.size
mode = img.mode
print(f"Image Size: {width}x{height}")
print(f"Image Mode: {mode}")
print(f"Number of Channels: {len(mode)}")
zero_count = 0
non_zero_counts = {}
for y in range(height):
for x in range(width):
pixel = img.getpixel((x, y))
if pixel == 0:
zero_count += 1
else:
if pixel in non_zero_counts:
non_zero_counts[pixel] += 1
else:
non_zero_counts[pixel] = 1
print("Zero pixel count:", zero_count)
if non_zero_counts:
print("Non-zero pixel values and their counts:")
for pixel, count in non_zero_counts.items():
print(f"Pixel value: {pixel}, Count: {count}")
else:
print("No non-zero pixel values found in the image.")
except FileNotFoundError:
print("File not found.")
And this was the output (giving for one image as example): Image Size: 1920x1080 Image Mode: P Number of Channels: 1 Zero pixel count: 1905463 Non-zero pixel values and their counts: Pixel value: 2, Count: 132729 Pixel value: 3, Count: 22865 Pixel value: 1, Count: 12543
I will try with the values you suggested. Thank you.
I retrained the model as suggested by you by using the mask images with pixel values 0, 85, 170 and 255 and I am still getting the same result (completely black and empty mask) by using predict.
The training masks which I use are like: Image Size: 1920x1080 Image Mode: L Number of Channels: 1 Zero pixel count: 1949404 Non-zero pixel values and their counts: Pixel value: 170, Count: 86534 Pixel value: 255, Count: 10566 Pixel value: 85, Count: 27096
And the mask the predict.py script creates are like: Image Size: 1920x1080 Image Mode: L Number of Channels: 1 Zero pixel count: 2073600 No non-zero pixel values found in the image.
Can there be something else going wrong?
sure what is the validation/testing accuracy ? what is the training accuracy. if its possible to share the code/notebook kindly share it to inocajith21.5@gmail.com i will look into it.
Hi, so I have trained the model to segment my custom dataset into multiple classes (different zones of the object). My masks are having 0, 1, 2 and 3 as pixel values to represent backgound and the 3 zones of the object. However, when I try to run predict.py it generates completely black masks, I tried to parse through the image to check if it contains any non-zero values and found out that all pixels are zeros. Is there anywhere in the training or prediction code I would have to change to accommodate my requirements? I gave the number of classes as 4 in training and prediction arguments, is that incorrect? Should I have given 3 as perhaps you don't count background as a class?