-
-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use an already trained Keras model to predict on lots of data #35
Comments
FYI, I started on this at https://gist.github.com/TomAugspurger/2889a052b5fec4d691f83ba2062d2d92 As you predicted I stopped as soon as I hit an error, and didn't do any profiling yet. I'll pick it up again soon, but don't want else to duplicate effort. |
That's great. When I started looking into this I quickly became lost on
how to set up the problem. You appear to have enough practical experience
that that's not much of an issue for you.
I'll put this on my TODO list. Now that there is a clear thing to
optimize/fix it's much easier for me.
…On Thu, Oct 25, 2018 at 5:29 PM Tom Augspurger ***@***.***> wrote:
FYI, I started on this at
https://gist.github.com/TomAugspurger/2889a052b5fec4d691f83ba2062d2d92
As you predicted X.map_blocks(model.predict) was slow.
I stopped as soon as I hit an error, and didn't do any profiling yet. I'll
pick it up again soon, but don't want else to duplicate effort.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#35 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASszEclxY5admrzWVLQctian5DR8h5qks5uoi0ogaJpZM4WV1oF>
.
|
Oh, and |
Right I think I'm stalled on deserializing the TensorFlow graph in a new process https://gist.github.com/33efb49efe611701ef122f577d0e0430 |
Probably putting this on the backburner for now, if others want to take a look. |
@TomAugspurger @mrocklin Once we have our data = [dd.array.from_delayed(x, shape=(224,224, 3),dtype=np.float32) for x in images]
nb_batches = 100
for i in range(100):
batch_images, batch_labels = next(data) #just an example to show.
model.train_on_batch(batch_images, batch_labels) Is there any way to do this? |
It depends on what you mean by "batch" I guess. You can slice into x in a variety of ways index = np.random.randint(0, x.shape[0], size=10)
batch = x[index] Some ways of slicing will be cheap (like above), some won't, depending on chunk structure. |
Thanks @mrocklin I would elaborate a bit on that. Say I have Now, with a simple python generator we are using only one core. So, instead of using a python generator, let us say we get data = [dd.array.from_delayed(x, shape=(224,224, 3),dtype=np.float32) for x in images] The shape of the final array would be |
The same as you would with NumPy for i in range(0, x.shape[0], 32):
chunk = x[i:i+32, ...] chunk is a dask array here. I'm not sure if that's what you want. You might want to call compute or delay the fit call (although Keras has issues sometimes with moving to other threads). |
Cool. Thanks a lot for your time. Yeah, I am aware of those issues, and that is why I just want to use |
@AakashKumarNain I have a similar use case, did you find performance improvements when transitioning from Numpy to dask, reading image slices from file? |
@AakashKumarNain same question on this. What code did you end up using? How was the performance? I want to use a keras.utils.Sequence subclass to leverage keras fit_generator, so I'm thinking something that keeps the images in a dask array and then loads each batch into memory:
|
@skeller88 I didn't try it. I was trying to benchmark it with tf.dataset. But this certainly looks good to this point. |
@mrocklin I think I'm stumbling on the exact issue "#maybe bad" mentioned at the top. psuedo code (working on reproducible) We have a large number of numpy arrays (geospatial tiles) and an object detection model. This works in serial.
Following your thought from above,
has some sort of multiprocessing tensorflow error
one level up on traceback is
testing on LocalCluster on CPU, but will eventually move to SLURM with GPUs. perhaps related to (dask/distributed#878, dask/dask-ml#281)
|
I created a working example here for those who find this link: dask/distributed#2333 |
This keeps coming up. I'm adding it to the core maintenance project board. |
@mrocklin happy to help if I can with tests, I use this kind of workflow
frequently with dask-jobqueue for submitting to GPU clusters
On Sat, May 23, 2020 at 10:16 AM Matthew Rocklin ***@***.***> wrote:
This keeps coming up. I'm adding it to the core maintenance project board.
https://stackoverflow.com/questions/61924824/how-to-do-model-predict-using-distributed-dask-with-a-pre-trained-keras-model
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#35 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJHBLA3DWCZVLP33LRE523RTAAITANCNFSM4FSXLICQ>
.
--
Ben Weinstein, Ph.D.
Postdoctoral Fellow
University of Florida
http://benweinstein.weebly.com/
|
A common approach is to train on a bit of data and then use that trained model to predict on lots of data. We could do this using ParallelPostFit in dask-ml, or we can use
X.map_blocks
ordf.map_partitions
. In either case we might want to be a bit careful about avoiding repeated serializations costs. For example, in the following case I suspect that we include the serialized model in every taskIt's probably better to encourage the user to keep the model delayed
We should also ensure that dask-ml does this correctly, and includes the model as a single task in the graph so that it gets sent around appropriately (cc @TomAugspurger )
I'm also generally curious if a Keras model that lives on the GPU will eventually make its way back onto the GPU when deserializing.
The text was updated successfully, but these errors were encountered: