Giter Club home page Giter Club logo

aicity-2021-track4's People

Contributors

endeavour10020 avatar

Watchers

 avatar  avatar

aicity-2021-track4's Issues

Suggestions for upcoming code

I have tested several anomaly detection repositories source code, and most of them didn't work. I have some advice for the upcoming code

Essential

  • Test it on a single purpose container like Docker (or you can just use Google Colab if you want). A base image like Ubuntu 18 is a good start to track if there are dependencies that must be specified in a requirements.txt file.

  • Prefer to use pathlib over os module or raw string for paths.

  • Use absolute paths over relative paths to allow the scripts to run wherever the user is executing them.

  • Use argparse to input paths (e.g. paths of directory). The following is a good example

import argparse
import pathlib


def parse_cli() -> argparse.ArgumentParser:
    current_directory = pathlib.Path(__file__).resolve().parent
    parser = argparse.ArgumentParser(description="Extract frames from directory containing videos.")
    parser.add_argument("--root", type=pathlib.Path, help="directory containing videos to be processed",
                        default=current_directory / "sample_video")
    parser.add_argument("--ext", type=str, help="extensions of the videos within the directory to be processed",
                        default="mp4")

    return parser
  • Do not use something like for i in range(1, 101) to iterate video files. If a video doesn't have a name like 1.mp4, this won't work. Iterate them like pathlib objects and convert it to str when using OpenCV.
  • Store data in JSON format over plain txt (unless it is just a list of strings like paths) or pickle files.
  • If it will have links to download stuff like pre-trained weights or models, have different server options in case they get broken at some point. For example: Google Drive, Dropbox, etc.
  • Add a Python gitignore to avoid committing unnecessary stuff.
  • Use an IDE like Pycharm to inspect code, reformat it and catch some early bugs if possible. It's helpful to ensure that your code has some style.
  • Measure the time a script takes to run
import time

def main(args: argparse.Namespace) -> int:
    start_time = time.perf_counter()

    # Some code
    
    end_time = time.perf_counter()
    res = time.strftime("%Hh:%Mm:%Ss", time.gmtime(end_time - start_time))
    print(f"Finished in {res}")
    return 0

if __name__ == "__main__":
    main(parse_cli().parse_args())

The reason of encapsulating the running code within the main function, you can find it in main โ€” Top-level code environment

Optional

  • Use decord like a cv2 style for random access.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.