-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add MovingMNIST dataset #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution. Can you explain what was the issue with tfds.feature.Video ?
# sequence = tfds.features.Image(shape=shape) | ||
|
||
# as video - doesn't work with 1 as final dim? | ||
# sequence = tfds.features.Video(shape=shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Video should works.
tfds.features.Video(shape=(seq_lenqth, height, width, 1))
If not, this is a bug from our end. Which error are you seeing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this @jackd! And yes, let's try to get Video to work.
Well that was a fun rabbit hole to dive down. Found/fixed a bug in numpy related to That being said, I feel the fixed implementation of |
@@ -61,6 +62,8 @@ def __init__(self, shape): | |||
raise ValueError('Video shape should be of rank 4') | |||
if shape.count(None) > 1: | |||
raise ValueError('Video shape cannot have more than 1 unknown dim') | |||
if shape[-1] not in (1, 3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove. The test is already in Image() called bellow: https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/core/features/image_feature.py#L108
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, but does this mean videos with 0 or 2 channels are also accepted? In the interest of keeping documentation up to date (had me confused initially when it said channels had to be 3).
@@ -260,7 +260,7 @@ def np_to_list(elem): | |||
return elem | |||
elif isinstance(elem, np.ndarray): | |||
elem = np.split(elem, elem.shape[0]) | |||
elem = np.squeeze(elem, axis=0) | |||
elem = [np.squeeze(e, axis=0) for e in elem] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Thanks for fixing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to go away and come back before realizing there was a much better way of doing this, unless I'm failing to appreciate some corner cases (elements won't automatically be converted np arrays... but given the name, I'm guessing that shouldn't be relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dataset looks good, but I'm not sure about accepting the moving_sequence
module into TFDS. The videos are usable in an ML model as-is; what is moving_sequence
useful for?
The In the interest of reproducibility I think it's appropriate to package them together. Anyone wanting to test on this dataset will, presumably, want a similar dataset to train with, and accessing it from the same source as the test data makes sense to me. How one packages it is another question, and I'm open to suggestions. My original implementation of
Someone could just make those decisions (or A lot of these questions above are related to dynamically generated datasets in general (or those involving non-trivial mapping operations at least). Does |
Thank you for explaining! I think you made the right call to only include the test data and to include this function here so that users can create the moving sequences themselves from the MNIST dataset. My main request is that we limit the surface area for the new module to just the 1 key method and to add a test for |
No disagreement here. I've added a few more optional kwargs to the main function in place of other publicly visible functions and adjusted for dynamic sizing, but the implementation remains very much the same. |
... lunch-time brought the revelation that I'm overcomplicating this trying to do this for multiple images in one shot - and that removing the |
Thanks! Simpler is better, especially when considering maintenance cost.
Doing things for one image at a time sounds good. Update here when it’s
ready for another look.
…On Sun, Feb 3, 2019 at 8:25 PM Dominic Jack ***@***.***> wrote:
... lunch-time brought the revelation that I'm overcomplicating this
trying to do this for multiple images in one shot - and that removing the
foldl entirely is likely much easier. Will make changes and fix test
errors now...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#28 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABEGW_9G0471HxCi8Shop_kuxGiIIT9Yks5vJ7ZWgaJpZM4aVdwD>
.
|
Finally, an excuse to play with tf 2.0 :). Merged in master changes and updated to single-image implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just a few little things in the test and then we're good to go!
ack, just found tf 2.0 bug with Update: I have no idea how |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! Will merge after I've verified on my end that the dataset generates ok.
PiperOrigin-RevId: 232784325
return tf.math.minimum(2 - points, points) | ||
|
||
|
||
def _get_random_unit_vector(ndims=2, dtype=tf.float32): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current code generates the direction from a normal distribution. I believe this is not what the original code does which generates the direction uniformly.
Please see:
line 245 in data_handlers.py in http://www.cs.toronto.edu/~nitish/unsupervised_video/unsup_video_lstm.tar.gz
where the direction is sampled uniformly from 0 - 2*pi
Is that correct or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see someone's actually reading the code! The original takes a unit vector with angle sampled uniformly. Here we take random normal coordinates and normalize them. The resulting distributions are equivalent. See e.g. alternative method 1 or convince yourself with the below code.
import numpy as np
import matplotlib.pyplot as plt
n = 100000
x, y = np.random.normal(size=(2, n))
angle = np.arctan2(y, x)
plt.hist(angle)
plt.show()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, cool thanks!
moving_sequence
doesn't actually provide a dataset per-se, but it's obviously strongly linked tomoving_mnist
. Not sure if that's precisely what this repo is intended for, but had fun writing it (and watching bouncing shoes/coats fromfashion_mnist
was interesting).