Are you sure you want to delete this access key?
comments | description | keywords |
---|---|---|
true | Learn how to visualize YOLO inference results directly in a VSCode terminal using sixel on Linux and MacOS. | YOLO, inference results, VSCode terminal, sixel, display images, Linux, MacOS |
Image from the libsixel website.
When connecting to a remote machine, normally visualizing image results is not possible or requires moving data to a local device with a GUI. The VSCode integrated terminal allows for directly rendering images. This is a short demonstration on how to use this in conjunction with ultralytics
with prediction results.
!!! warning
Only compatible with Linux and MacOS. Check the [VSCode repository](https://github.com/microsoft/vscode), check [Issue status](https://github.com/microsoft/vscode/issues/198622), or [documentation](https://code.visualstudio.com/docs) for updates about Windows support to view images in terminal with `sixel`.
The VSCode compatible protocols for viewing images using the integrated terminal are sixel
and iTerm
. This guide will demonstrate use of the sixel
protocol.
First, you must enable settings terminal.integrated.enableImages
and terminal.integrated.gpuAcceleration
in VSCode.
"terminal.integrated.gpuAcceleration": "auto" # "auto" is default, can also use "on"
"terminal.integrated.enableImages": true
Install the python-sixel
library in your virtual environment. This is a fork of the PySixel
library, which is no longer maintained.
pip install sixel
Load a model and execute inference, then plot the results and store in a variable. See more about inference arguments and working with results on the predict mode page.
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt")
# Run inference on an image
results = model.predict(source="ultralytics/assets/bus.jpg")
# Plot inference results
plot = results[0].plot() # (1)!
Now, use OpenCV to convert the np.ndarray
to bytes
data. Then use io.BytesIO
to make a "file-like" object.
import io
import cv2
# Results image as bytes
im_bytes = cv2.imencode(
".png", # (1)!
plot,
)[1].tobytes() # (2)!
# Image bytes as a file-like object
mem_file = io.BytesIO(im_bytes)
1
that is returned is needed.Create a SixelWriter
instance, and then use the .draw()
method to draw the image in the terminal.
from sixel import SixelWriter
# Create sixel writer object
w = SixelWriter()
# Draw the sixel image in the terminal
w.draw(mem_file)
!!! danger
Using this example with videos or animated GIF frames has **not** been tested. Attempt at your own risk.
import io
import cv2
from sixel import SixelWriter
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt")
# Run inference on an image
results = model.predict(source="ultralytics/assets/bus.jpg")
# Plot inference results
plot = results[0].plot() # (3)!
# Results image as bytes
im_bytes = cv2.imencode(
".png", # (1)!
plot,
)[1].tobytes() # (2)!
mem_file = io.BytesIO(im_bytes)
w = SixelWriter()
w.draw(mem_file)
1
that is returned is needed.!!! tip
You may need to use `clear` to "erase" the view of the image in the terminal.
To view YOLO inference results in a VSCode terminal on macOS or Linux, follow these steps:
Enable the necessary VSCode settings:
"terminal.integrated.enableImages": true
"terminal.integrated.gpuAcceleration": "auto"
Install the sixel library:
pip install sixel
Load your YOLO model and run inference:
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
results = model.predict(source="path_to_image")
plot = results[0].plot()
Convert the inference result image to bytes and display it in the terminal:
import io
import cv2
from sixel import SixelWriter
im_bytes = cv2.imencode(".png", plot)[1].tobytes()
mem_file = io.BytesIO(im_bytes)
SixelWriter().draw(mem_file)
For further details, visit the predict mode page.
The sixel protocol is currently only supported on Linux and macOS because these platforms have native terminal capabilities compatible with sixel graphics. Windows support for terminal graphics using sixel is still under development. For updates on Windows compatibility, check the VSCode Issue status and documentation.
If you encounter issues displaying images in the VSCode terminal using sixel:
Ensure the necessary settings in VSCode are enabled:
"terminal.integrated.enableImages": true
"terminal.integrated.gpuAcceleration": "auto"
Verify the sixel library installation:
pip install sixel
Check your image data conversion and plotting code for errors. For example:
import io
import cv2
from sixel import SixelWriter
im_bytes = cv2.imencode(".png", plot)[1].tobytes()
mem_file = io.BytesIO(im_bytes)
SixelWriter().draw(mem_file)
If problems persist, consult the VSCode repository, and visit the plot method parameters section for additional guidance.
Displaying video inference results or animated GIF frames using sixel in the terminal is currently untested and may not be supported. We recommend starting with static images and verifying compatibility. Attempt video results at your own risk, keeping in mind performance constraints. For more information on plotting inference results, visit the predict mode page.
python-sixel
library?To troubleshoot issues with the python-sixel
library:
Ensure the library is correctly installed in your virtual environment:
pip install sixel
Verify that you have the necessary Python and system dependencies.
Refer to the python-sixel GitHub repository for additional documentation and community support.
Double-check your code for potential errors, specifically the usage of SixelWriter
and image data conversion steps.
For further assistance on working with YOLO models and sixel integration, see the export and predict mode documentation pages.
Press p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?