Giter VIP home page Giter VIP logo

Comments (13)

JanuszL avatar JanuszL commented on May 15, 2024 2

I just prepared some example based on your experience, #58.

from dali.

cliffwoolley avatar cliffwoolley commented on May 15, 2024 1

What's the next step to improve this one? Do we need to document the example better, improve it generally, ... ?

from dali.

JanuszL avatar JanuszL commented on May 15, 2024 1

I think we need to provide example with different readers doing the same at the end.

from dali.

ptrendx avatar ptrendx commented on May 15, 2024

Hmm, that's strange - @Kh4L could you look at it?

from dali.

JanuszL avatar JanuszL commented on May 15, 2024

Hi,
For me following code works (corrected some errors from your example):

class FileReadPipeline(Pipeline):
    def __init__(self,batch_size, num_threads, device_id):
        super(FileReadPipeline, self).__init__(batch_size, num_threads, device_id, seed = 12)
        self.input = ops.FileReader(file_root = image_dir, random_shuffle = True, initial_fill = 21)
        self.decode = ops.nvJPEGDecoder(device = "mixed", output_type = types.RGB)
        self.resize = ops.Resize(device = "gpu", random_resize = True, 
                                resize_a = 256, resize_b = 480,
                                image_type = types.RGB,
                                interp_type = types.INTERP_LINEAR)
        self.cmn = ops.CropMirrorNormalize(device = "gpu",
                                            output_dtype = types.FLOAT,
                                            crop = (227, 227),
                                            image_type = types.RGB,
                                            mean = [128., 128., 128.],
                                            std = [1., 1., 1.])
        self.uniform = ops.Uniform(range = (0.0, 1.0))

    def define_graph(self):
        jpegs, labels = self.input()
        images = self.decode(jpegs)
        resized_images = self.resize(images)
        output = self.cmn(resized_images, crop_pos_x = self.uniform(),
                        crop_pos_y = self.uniform())
        # images are on the GPU
        return (output, labels.gpu())

I will check TFRecordPipeline too later.

from dali.

jxmelody avatar jxmelody commented on May 15, 2024

Hi @JanuszL ,
Thanks for your reply.
I checked my code and I found it's somewhere confusing cause I changed it before I raise this issue... so I modified it.
Actually, the most confused question of me is the serialize part ... What's the diffrence between serialized pipeline and non-serialized pipeline ?must serialized pipeline when using tensorflow ?
At last, I noticed that your code above are different with mine in last line:

return (output, labels,.gpu())
#return (output,labels)

So, is the .gpu() neccessary?

(sorry, I cant run the code right now,but I will check if the change can work tommrow (9 hours later... ), thanks again ;))

from dali.

Kh4L avatar Kh4L commented on May 15, 2024

Hi @jxmelody ,
For TFRecordPipeline you have to define the graph by overriding def define_graph(self):.

As @JanuszL wrote, in FileReadPipeline you are returning images that is images = self.decode(jpegs). You actually want to return output (from CropMirrorNormalize).

Yes, .gpu() is necassary because FileReader returns CPU Tensors and tensorflow-gpu expects only GPU Tensors as Output.
So your define_graph's should return

return (output, labels.gpu())

The serialized pipeline is a string representing your pipeline in protobuf format: it contains parameters and the graph defined in Python. Our DALI-Tensorflow op needs this serialized pipeline to build and run internally the actual DALI Pipeline.

from dali.

jxmelody avatar jxmelody commented on May 15, 2024

Hi @Kh4L ,
Sorry ... I forgot to paste the define_graph function of TFRecordPipeline , but I actually wrote this function and that not work... Anyway, I will add it to my code above, and you can check this.

For FileReaderPipeline, by correcting the errors as @JanuszL wrote, it can work now, It's my mistake. Thank both of you!

But TFRecordPipeline still can not work ,even though I have return .gpu() as you said .

Thank you for explaining the serialization . So as far as I understand, it's necessary to serialize the pipline first before use sess.run([image, label]), isn't it?

from dali.

JanuszL avatar JanuszL commented on May 15, 2024

Hi,
Yes, indeed you need to serialize the pipeline first, then use it to initialize daliop. Please follow TensorFlow-ResNet50 example.
TFRecordPipeline works for me. You need to use image/class/label as labels, image/class/text is rather human-readable representation not meant for training.

class TFRecordPipeline(Pipeline):
    def __init__(self, batch_size, num_threads, device_id):
        super(TFRecordPipeline, self).__init__(batch_size,
                                        num_threads,
                                        device_id)
        self.input = ops.TFRecordReader(path = tfrecord, 
                                        index_path = tfrecord_idx,
                                        features = {"image/encoded" : tfrec.FixedLenFeature((), tfrec.string, ""),
                                        'image/class/label':         tfrec.FixedLenFeature([1], tfrec.int64,  -1)
                                        })
        self.decode = ops.nvJPEGDecoder(device = "mixed", output_type = types.RGB)
        self.resize = ops.Resize(device = "gpu", resize_a = 256, resize_b = 256)
        self.cmnp = ops.CropMirrorNormalize(device = "gpu",
                                            output_dtype = types.FLOAT,
                                            crop = (224, 224),
                                            image_type = types.RGB,
                                            mean = [0., 0., 0.],
                                            std = [1., 1., 1.])
        self.uniform = ops.Uniform(range = (0.0, 1.0))

    def define_graph(self):
        inputs = self.input()
        images = self.decode(inputs["image/encoded"])
        resized_images = self.resize(images)
        output = self.cmnp(resized_images, crop_pos_x = self.uniform(),
                        crop_pos_y = self.uniform())
        return (output, inputs["image/class/label"].gpu())

from dali.

JanuszL avatar JanuszL commented on May 15, 2024

Tracked internally in DALI-133

from dali.

jxmelody avatar jxmelody commented on May 15, 2024

@JanuszL thanks, you are right . I changed texts to label, then it works!

from dali.

JanuszL avatar JanuszL commented on May 15, 2024

Just merged #58.
It will be included in next minor release.

from dali.

biswajitcsecu avatar biswajitcsecu commented on May 15, 2024

it is working.

from dali.

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.