Giter VIP home page Giter VIP logo

Comments (5)

Hakuyume avatar Hakuyume commented on July 27, 2024

How about always returning a dictionary which contains drawn parameters.
Here is an example.

dst_img, params = random_expand(src_img)
# params: {'ratio': ***, 'x_offset': ***, 'y_offset': ***}

dst_img, params = random_crop(src_img, (***, ***))
# params: {'x_slice': ***, 'y_slice': ***}

If users do not need params, they can write

dst_img, _ = random_*(src_img, ...)

from chainercv.

yuyu2172 avatar yuyu2172 commented on July 27, 2024

I think what you proposed is simple and nice.
However, I have a concern that it is not clear as to which transforms return params.

For example, center_crop returns params too. Also, I think ten_crop should return it too (it does not in status quo). These parameters become helpful when users want to use center_crop together with other data types (e.g. bounding boxes).

from chainercv.

yuyu2172 avatar yuyu2172 commented on July 27, 2024

There are three options

  • making params optional for random_* and transforms such as center_crop
  • params is not optional for random_*, but optional for center_crop
  • params is not optional for all transforms.

from chainercv.

Hakuyume avatar Hakuyume commented on July 27, 2024

I think the third option is the best. In this case, all functions without computed params, such as flip and pad, should return empty dictionaries.

from chainercv.

yuyu2172 avatar yuyu2172 commented on July 27, 2024

Thanks for your opinion.
I think that there is still a room left on how to decide parameter convention for transforms that act on non-
image data types.
If we make those transforms to return params as well, I think that it looks redundant and in most cases unnecessary.
Instead, if we do not make those transforms to return params, it would defeat the purpose because consistency will be lost. Also, this would not work in the case when transforms on non-image need to return param.

Considering those points, I would rather make all transforms to have optional parameter return_params if necessary.

I compared both options in some example codes I had.

Semantic Segmentation Example (one in examples)

    # prepare datasets
    def transform(in_data):
        img, label = in_data
        vgg_subtract_bgr = np.array(
            [103.939, 116.779, 123.68], np.float32)[:, None, None]
        img -= vgg_subtract_bgr
        img, _ = transforms.pad(img, max_size=(512, 512), bg_value=0)
        label, _ = transforms.pad(label, max_size=(512, 512), bg_value=-1)
        return img, label

Detection example (with no return_param)

def transform(in_data):
    img, bbox = in_data
    img -= np.array([103.939, 116.779, 123.68])[:, None, None]

    # Resize bounding box to a shape
    # with the smaller edge at least at length 600
    input_shape = img.shape[1:]
    img, _ = transforms.scale(img, 600)
    output_shape = img.shape[1:]
    bbox, _ = transforms.resize_bbox(bbox, input_shape, output_shape)

    # horizontally flip
    img, params = transforms.random_flip(img, x_random=True)
    bbox, _ = transforms.flip_bbox(bbox, output_shape, params['x_flip'])
    return img, bbox

Detection example (with return_param)

def transform(in_data):
    img, bbox = in_data
    img -= np.array([103.939, 116.779, 123.68])[:, None, None]

    # Resize bounding box to a shape
    # with the smaller edge at least at length 600
    input_shape = img.shape[1:]
    img = transforms.scale(img, 600)
    output_shape = img.shape[1:]
    bbox = transforms.resize_bbox(bbox, input_shape, output_shape)

    # horizontally flip
    img, param = transforms.random_flip(img, x_random=True, return_param=True)
    bbox= transforms.flip_bbox(bbox, output_shape, param['x_flip'])
    return img, bbox

from chainercv.

Related Issues (20)

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.