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

Something about the code smell #57

Closed
rockyzhengwu opened this issue Jun 14, 2020 · 2 comments
Closed

Something about the code smell #57

rockyzhengwu opened this issue Jun 14, 2020 · 2 comments

Comments

@rockyzhengwu
Copy link

rockyzhengwu commented Jun 14, 2020

thanks for your work first

I just start to read the code in utils/datasets.py , May be can give you some advice about the code, you can just ignore this or think about it.

some example
1, may be this can use a function not just write in the init ,

 try:
            path = str(Path(path))  # os-agnostic
            parent = str(Path(path).parent) + os.sep
            if os.path.isfile(path):  # file
                with open(path, 'r') as f:
                    f = f.read().splitlines()
                    f = [x.replace('./', parent) if x.startswith('./') else x for x in f]  # local to global path
            elif os.path.isdir(path):  # folder
                f = glob.iglob(path + os.sep + '*.*')
            else:
                raise Exception('%s does not exist' % path)
            self.img_files = [x.replace('/', os.sep) for x in f if os.path.splitext(x)[-1].lower() in img_formats]
        except:
            raise Exception('Error loading data from %s. See %s' % (path, help_url))

like this


def load_image_files(path):
    path = str(Path(path))
    parent = str(Path(path).parent) + os.sep
    if os.path.isfile(path):
        with open(path, 'r') as f:
            image_names = f.read().splitlines()
            image_names = [x.replace('./', parent) if x.startswith('./') else x for x in image_names]
    elif os.path.isdir(path):
        image_names = glob.iglob(path + os.sep + '*.*')
    else:
        raise Exception('%s does not exist' % path)
    img_files = [name.replace('/', os.sep) for name in image_names if
                      os.path.splitext(name)[-1].lower() in IMG_FORMATS]
    return img_files

  1. I think you can name ar to aspect_ratio not comment behind
  ar = s[:, 1] / s[:, 0]  # aspect ratio

there are some other like this two, but i think this is not import ,
in fact , i'm not sure if i want to summit this issues , because i also not write clean code.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 14, 2020

Hello @rockyzhengwu, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

@glenn-jocher
Copy link
Member

@rockyzhengwu thanks for your feedback! You are right that the code could use some cleanup. Best practices is to drop code into functions when it repeated elsewhere, but in this case I believe this is the only location this code block is used.

In any case there is improvement that could be made in variable naming and error checking in this code region like you mention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants