Resources are an easy way to manage large files that transforms need and are not included on easycv by default. Examples of such files are datasets and pre-trained models.
Creating a resource¶
Resources are represented by a YAML file. You can manually create this file or use the built-in resource creator.
Using resource creator¶
The following script creates a resource.
from easycv.resources import create_resource create_resource() >>> Resource name: test-resource >>> Number of files: 1 >>> File 1 name: file1.txt >>> File 1 url: example.com/file1.txt >>> Downloading/hashing files... >>> Resource created successfully
A resource can be represented by YAML file. We could create the resource described above with the following file:
To add this resource to easycv, save the file as test-resource.yaml and put it inside easycv\resources\sources.
Resources can be used inside transforms to access big files that don’t ship with EasyCV by default.
For example, if you want to create a transform that uses a pre-trained neural network you can create a resource that represents the weights file. Then on your transform, if you require the resource, EasyCV downloads the resource automatically when the transform is used.
Let’s create a transform called TestTransform that uses the resource we created above. We can obtain a path to the file by using
from easycv.resources import get_resource from easycv.transforms.base import Transform class TestTransform(Transform): def process(self, image, **kwargs): file = get_resource("test-resource", "file1.txt") (...) # do something with the file and the image return image