Roboflow’s Python Pip Package For Computer Vision

Regardless of whether your project is a new product line, a new industrial production system, RPA solution integration, a research project, or a personal project to help you learn what computer vision is all about, you'll want to add pip install roboflow to your code - and here's why.

Depending on your locale, you may refer to it as computer vision, machine vision, digital transformation (DX), or Robotic Process Automation (RPA).

No matter what you name it, this simple command will help bring your computer vision project to life:

pip install roboflow

You can use the Roboflow pip package to:

Programmatically download or export images in multiple formats from your dataset; upload images and annotations; upload frames from videos; run inference on a trained version of your dataset; and quickly improve your model's performance with Active Learning.

Start Sample Code

Still skeptical if this is useful? Here's an example:

What would it look like if you were trying to implement more automated safety checks for workers at your factory and quality analysis on products coming from the factory line?

You decide to create an automated system based on computer vision that will help to identify and alert the relevant parties when applicable, for things like:

  1. (Unauthorized) people or items present in dangerous or restricted areas of the factory floor or the surrounding property.
  2. Detecting whether employees are wearing the proper safety equipment, and in the correct zones of the factory floor.
  3. Identifying defects in raw materials or finished products, such as missing or misassembled components, as they move down the factory line.
  4. Identifying other potentially risky or life-threatening situations on the factory line before they can cause harm or shutdowns, i.e detecting products in dangerous or incorrect orientations before they proceed far enough to cause jams or injuries.

You [and your team] decide to use Roboflow and the pip package to help you create and deploy your model(s) faster. After creating the model(s) you take the necessary intermediary steps, such as implementing one of Roboflow's easy deployment options, and your vision solution is now in production!

But wait - there are some subtle, or in some cases, glaring problems. Your model is presenting false detections or failing to make detections when there should be one.

All that work, to have another problem to solve. Here's the catch, the problem is actually already solved with Active Learning.

pip install roboflow to the rescue.

Here's how you can implement Active Learning with the Roboflow Python package in your production environment:

from roboflow import Roboflow
import json

# private api key found in Roboflow > YOURWORKSPACE > Roboflow API
# NOTE: this is your private key, not publishable key!
# https://docs.roboflow.com/rest-api#obtaining-your-api-key
private_api_key = "INSERT API KEY HERE"

# gain access to your workspace
rf = Roboflow(api_key=private_api_key)
workspace = rf.workspace()

# you can obtain your model path from your project URL, it is located
# after the name of the workspace within the URL - you can also find your
# model path on the Example Web App for any dataset version trained
# with Roboflow Train
# https://docs.roboflow.com/inference/hosted-api#obtaining-your-model-endpoint
model_path = "INSERT MODEL PATH HERE"
project = workspace.project(f"{model_path}")

# be sure to replace with a path to your file
# if you run this in Colab, be sure to upload the file to colab, hover over
# the file name, and select the 3 dots on the right of the file name to copy
# the file path, and paste it as the value for "imgpath"
img_path = "INSERT IMAGE PATH HERE"

# establish number of retries to use in case of upload failure
project.upload(f"{img_path}", num_retry_uploads=3)

Active Learning Conditionals

from roboflow import Roboflow
# obtaining your API key: https://docs.roboflow.com/rest-api#obtaining-your-api-key
rf = Roboflow(api_key="INSERT_PRIVATE_API_KEY")
workspace = rf.workspace()


raw_data_location = "INSERT_PATH_TO_IMAGES"
raw_data_extension = ".jpg" # or ".png", ".jpeg" depending on file type

# replace * with your model version number for inference
inference_endpoint = ["INSERT_MODEL_ID", *]
upload_destination = "INSERT_MODEL_ID"
# set the conditionals values as necessary for your active learning needs
conditionals = {
    "required_objects_count" : 1,
    "required_class_count": 1,
    "target_classes": [],
    "minimum_size_requirement" : float('-inf'),
    "maximum_size_requirement" : float('inf'),
    "confidence_interval" : [10,90],
}

# filtering out images for upload by similarity is available for paid plans
# contact the Roboflow team for access: https://roboflow.com/sales
# conditionals = {
#     "required_objects_count" : 1,
#     "required_class_count": 1,
#     "target_classes": [],
#     "minimum_size_requirement" : float('-inf'),
#     "maximum_size_requirement" : float('inf'),
#     "confidence_interval" : [10,90],
#     "similarity_confidence_threshold": .3,
#     "similarity_timeout_limit": 3
# }

workspace.active_learning(raw_data_location=raw_data_location, 
    raw_data_extension=raw_data_extension,
    inference_endpoint=inference_endpoint,
    upload_destination=upload_destination,
    conditionals=conditionals)

(1) Continuously Collect New Images at Random

Add logic in your code along with `pip install roboflow` to programmatically collect sample images or frames from a video feed at specific or randomized time intervals.

(2) Collect New Images Below a Given Confidence Threshold

Add logic in your code along with pip install roboflow to programmatically collect simple images or frames from a video feed where inference resulted in the model finding or classifying objects of interest below a given confidence threshold.

(3) Solicit Your Application's Users to Verify Model Predictions

Add logic in your code along with pip install roboflow and bug reports within your dashboard, mobile app, or however you have chosen to create your computer vision product. Use these bug reports to quickly identify ways to improve the functionality of your computer vision product, and most importantly, ensure that users have a model that is not only working well but primed to quickly improve.

From here, take any images or frames from videos in the bug reports and programmatically set them for return to Roboflow – or you can store/cache them on your deployment device or system for a future upload to Roboflow.

And just like that, we've prepared a consistent Machine Learning Operations (MLOps) Pipeline to produce models to classify one or many objects of interest, classify and locate or detect, and even mask objects of interest!

No matter how you choose to implement Active Learning, so long as you do it correctly with pip install roboflow, your model will quickly learn what to detect and what not to detect with increasing confidence in the environment(s) it is present in.

How to Get Started Today:

  1. Go to https://app.roboflow.com
  2. Create your Roboflow account
  3. Create your first workspace
  4. Locate your dataset, or search for one on Roboflow Universe
  5. Start you first project and generate your first dataset
  6. Grab your API key, and add pip install roboflow to your code.😎
  7. Active Learning Conditionals (Sample Code)

Build and Deploy with Roboflow for free

Use Roboflow to manage datasets, train models in one click, and deploy to web, mobile, or the edge. With a few images, you can train a working computer vision model in an afternoon.