In this short tutorial, you can try Towhee for yourself in this browser-based scenario. To begin, click the "Launch Terminal" button below.
Clicking on any of the code snippets below will automatically paste the contents of the snippet into the terminal you just launched. Once you close this page, the environment that you just spun up along with all of its contents will be wiped clean.
The browser-based terminal you just brought up is a completely clean environment, so we'll need to install Towhee first: (click the following command, it will be copied into the terminal)
First, install Towhee:
pip3 install towhee
If you want to install models in towhee, just run:
pip3 install towhee.models
Some prep work
Once Towhee is installed, let's move onto a bit of prep work.
Running your first pipeline
Now it's time to generate your first embedding with Towhee! Open up a
Data transformations are central to Towhee; Pipelines are simply a series of transformations connected together in a directed acyclic graph. All pre-built Towhee pipelines are given names that are representative of the task at hand. To create a pipeline, import the
pipeline function from
from towhee import pipeline
Now let's instantiate an image embedding pipeline:
p = pipeline('image-embedding')
Towhee allows users to specify an image via URL:
output = p('https://github.com/towhee-io/towhee/blob/main/docs/get-started/towhee.jpeg?raw=true')
That's it! The embedding vector for the corresponding input image (
towhee.jpeg) is stored in the
Using a local image
Alternatively, we can use a local image instead. Let's grab one:
image-embedding pipeline supports both HTTP (via the
requests library) and local paths. Run it through the pipeline as so:
output = p('towhee.jpeg')
Note that the default model used by
ResNet50 (you can find the corresponding mapping for default pipelines here). The default repository for this pipeline is located on the Towhee hub; following the link will take you to a README page describing the pipeline, the model(s) used, and a simple diagram explaining how data flows through the pipeline.
Prototyping ML applications
Towhee also provides
DataCollection - Pythonic method-chaining API for developing applications and running pipelines in just a couple lines of code. Let's import it first:
from towhee.functional import DataCollection
Now let's get the list of all numbers divisible by 7 between 0 and 99:
DataCollection.range(100).filter(lambda x: x % 7 == 0).to_list()
It's as easy as that! Feel free to continue trying - we have more examples here.
Once you're finished, be sure to quit out of the enviroment using: