Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Image] add random lighting #8779

Merged
merged 2 commits into from
Nov 22, 2017
Merged

Conversation

sxjscience
Copy link
Member

@sxjscience sxjscience commented Nov 22, 2017

Description

Add RandomLighting and AdjustLighting
#8556

import os
os.environ['MXNET_CPU_WORKER_NTHREADS'] = '1'
os.environ['OMP_NUM_THREADS'] = '1'
import time
import numpy as np
import multiprocessing as mp
import mxnet as mx
from mxnet import gluon as gl
from mxnet.gluon.data.vision import transforms

if __name__ == '__main__':
    M = 24
    BS = 100

    dataset = gl.data.vision.ImageFolderDataset('256_ObjectCategories')
    transform = transforms.Compose([transforms.RandomBrightness(1.0),
                                    transforms.RandomContrast(1.0),
                                    transforms.RandomSaturation(1.0),
                                    transforms.RandomLighting(0.05),
                                    transforms.ToTensor(),
                                    transforms.Normalize([0, 0, 0], [1, 1, 1])])
    dataset = dataset.transform_first(lambda x: transform(mx.image.center_crop(x, (224, 224))[0]))
    data_loader = gl.data.DataLoader(dataset, BS, shuffle=True, num_workers=M)

    N = len(dataset)

    iterator = iter(data_loader)

    tic = time.time()

    for data, label in iterator:
        data.wait_to_read()
        print(data.shape)

    print(N/(time.time() - tic))

@@ -151,3 +151,23 @@ def __init__(self, max_brightness=0, max_contrast=0, max_saturation=0, max_hue=0

def hybrid_forward(self, F, x):
return F.image.random_color_jitter(x, *self._args)


class AdjustLighting(HybridBlock):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Then I will directly call the operator in the testing code



class AdjustLighting(HybridBlock):
def __init__(self, alpha_rgb=(0.0, 0.0, 0.0), eigval=(55.46, 4.794, 1.148),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's alpha_rgb?
use base._Null for default arguments to avoid parsing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's (alpha_r, alpha_g, alpha_b)

float pca_g = alpha_r * eigvec[3] + alpha_g * eigvec[4] + alpha_b * eigvec[5];
float pca_b = alpha_r * eigvec[6] + alpha_g * eigvec[7] + alpha_b * eigvec[8];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge to one loop

@piiswrong piiswrong merged commit f33654b into apache:vision Nov 22, 2017
zhreshold pushed a commit to zhreshold/mxnet that referenced this pull request Dec 7, 2017
zhreshold pushed a commit to zhreshold/mxnet that referenced this pull request Dec 8, 2017
piiswrong pushed a commit to piiswrong/mxnet that referenced this pull request Jan 19, 2018
piiswrong pushed a commit that referenced this pull request Jan 22, 2018
* add random lighting

* fix
yuxiangw pushed a commit to yuxiangw/incubator-mxnet that referenced this pull request Jan 25, 2018
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants