-
Notifications
You must be signed in to change notification settings - Fork 7
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
Accuracy #13
Comments
One more. I used this code.
|
Better WeightsHi @deepsea920415, unfortunately, there's not much that can be done because the dataset is very small. Based on the data (standalone glasses) you are showing, I tried training a new segmenter = GlassesSegmenter(kind="lenses", size="large", weights="path/to/weights.pth") Here are two weight files:
Square InputsAlso, you might want to pad your image from both sides to make sure it is a square: OPTION 1: preprocess image filesimport os
from PIL import Image
from glasses_segmenter import GlassesSegmenter
# Both directories must already exist
INPUT_DIR = "path/to/non_square"
PREPROCESS_DIR = "path/to/square"
def make_image_square(image_path):
img = Image.open(image_path)
width, height = img.size
target_size = max(width, height)
new_img = Image.new(img.mode, (target_size, target_size), img.getpixel((0,0)))
left_padding = (target_size - width) // 2
top_padding = (target_size - height) // 2
new_img.paste(img, (left_padding, top_padding))
return new_img
for filename in os.listdir(INPUT_DIR):
img = make_image_square(os.path.join(INPUT_DIR, filename))
img.save(os.path.join(PREPROCESS_DIR, filename))
segmenter = GlassesSegmenter(kind="lenses", size="large", weights="path/to/weights.pth")
segmenter.process_dir(PREPROCESS_DIR) OPTION 2: extend GlassesSegmenterfrom glasses_detector import GlassesSegmenter
class MyGlassesSegmenter(GlassesSegmenter):
@staticmethod
def make_image_square(image_path):
img = Image.open(image_path)
width, height = img.size
target_size = max(width, height)
new_img = Image.new(img.mode, (target_size, target_size), img.getpixel((0,0)))
left_padding = (target_size - width) // 2
top_padding = (target_size - height) // 2
new_img.paste(img, (left_padding, top_padding))
return new_img
def predict(self, image_paths, *args, **kwargs):
# WARNING: image_paths must be a list of paths!
images = [self.make_image_square(path) for path in image_paths]
return super().predict(images, *args, **kwargs)
segmenter = MyGlassesSegmenter(kind="lenses", size="large", weights="path/to/weights.pth")
segmenter.process_dir("path/to/non_square") Further ImprovementsTo further improve accuracy, here are some further suggestions (they are, however, beyond the scope of this package):
|
Thank you. |
Yup, training on more data is the best way to go! |
Hello.
First of all, thanks for releasing this excellent project.
I tried to segment lenses from images.
But as you can see here, accuracy is not good.
Is there any way to improve the accuracy?
![BOSS_BOSS0521S_003_01](https://github.com/mantasu/glasses-detector/assets/15572169
4/4b480698-bf43-4778-8398-d282be9bd8f4)
Hope to please help me.
Thanks again.
The text was updated successfully, but these errors were encountered: