Coder Social home page Coder Social logo

unixpickle-car-data's Introduction

car-data

This is a hobby project to predict various attributes of cars from photos.

Demo and blog post:

Usage

First, you should:

  • Compile the scraper with cargo build --release.
  • Install the Python package with pip install -e ..

Scraping data

To run the scraper, run:

./target/release/car-data scrape-kbb /path/to/db.db /path/to/images

In the above command, /path/to/db.db is the path where the metadata will be saved. It is stored as a sqlite3 database. The /path/to/images directory will be used to dump raw images.

To deduplicate and downsample the downloaded images, run:

./target/release/car-data dedup-images \
    /path/to/db.db \
    /path/to/images \
    /path/to/dedup

From here on out, we will use the /path/to/dedup directory instead of /path/to/images, since the former directory contains all of the images we will actually use for training.

To export the resulting dataset as a .npz file to load in Python, run:

./target/release/car-data export-data \
    /path/to/db.db \
    /path/to/index.npz

Filtering the dataset

To filter the dataset, you will first want to compute feature vectors for the entire dataset. These will be exported as a directory full of npz files with shards of features. You can do this with the following command:

python3 -m car_data.scripts.clip_features \
    /path/to/dedup \
    /path/to/features

Once you have labeled some images for the filter, you can train it quickly like so:

python3 -m car_data.scripts.train_filter \
    --positive_dirs /path/to/positive_dir \
    --negative_dirs /path/to/negative_dir \
    --model_out /path/to/filter.pt

To filter the dataset .npz file using the filter, you can use this command:

python3 -m car_data.scripts.filter_index \
    --index /path/to/index.npz \
    --feature_dir /path/to/features \
    --classifier_path /path/to/filter.pt \
    --output_path /path/to/index_filtered.npz

Training a model

To train a MobileNetV2 with auxiliary losses:

python3 -m car_data.scripts.train \
    --index_path /path/to/index_filtered.npz \
    --image_dir /path/to/dedup \
    --save_dir /path/to/mobilenetv2_save_dir \
    --lr 1e-4 \
    --batch_size 64 \
    --eval_interval 1 \
    --use_data_aug \
    --model mobilenetv2

To finetune CLIP with auxiliary losses:

python3 -m car_data.scripts.train \
    --index_path /path/to/index_filtered.npz \
    --image_dir /path/to/dedup \
    --save_dir /path/to/clip_save_dir \
    --lr 1e-5 \
    --batch_size 64 \
    --microbatch 16 \
    --eval_interval 1 \
    --use_data_aug \
    --model clip

unixpickle-car-data's People

Contributors

unixpickle avatar

Watchers

 avatar

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.