Comments (13)
I just prepared some example based on your experience, #58.
from dali.
What's the next step to improve this one? Do we need to document the example better, improve it generally, ... ?
from dali.
I think we need to provide example with different readers doing the same at the end.
from dali.
Hmm, that's strange - @Kh4L could you look at it?
from dali.
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.
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.
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.
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.
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.
Tracked internally in DALI-133
from dali.
@JanuszL thanks, you are right . I changed texts to label, then it works!
from dali.
Just merged #58.
It will be included in next minor release.
from dali.
it is working.
from dali.
Related Issues (20)
- random_resized_crop does not support different image sizes HOT 13
- How exactly does distributing the dataset with DALI/TensorFlow work? HOT 3
- Video Reader performance and alternative considerations HOT 4
- `experimental_fetch_to_device` makes no difference since TF 2.14 HOT 2
- external_source doesn't return last incomplete batch HOT 5
- Video Reader sequence start and end HOT 3
- Is it possible to modify the labels according to the random rotation of images? HOT 5
- Create a pytorch dataloader with 2 data sources HOT 5
- Resize on CPU with output shape coming from an external source operator HOT 3
- webdataset error HOT 2
- AWS DALI video_loader error HOT 3
- why multi-gpu training slower than single gpu HOT 1
- How to manage empty items in a batch? HOT 5
- nvidia.dali.fn.python_function() failed with TypeError HOT 5
- Can I install DALI on CPU node without GPU/CUDA HOT 3
- fn.lookup_table giving wrong result for gpu HOT 5
- Need argmax/argmin operator HOT 1
- How to destory a pipeline? HOT 1
- random crop function HOT 10
- cv2.resize(interpolation=cv2.INTER_LINEAR) different with fn.resize(img, antialias=True, subpixel_scale=True, interp_type=types.DALIInterpType.INTERP_LINEAR, resize_y=target_img_height, max_size=max_width) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dali.