sxjscience / HKO-7

Source code of paper "[NIPS2017] Deep Learning for Precipitation Nowcasting: A Benchmark and A New Model"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pixel value larger than 255 when using movingmnist_iterator script to generate data

cunwang-root opened this issue · comments

my code using script to generate data

from nowcasting.movingmnist_iterator import MovingMNISTAdvancedIterator
import numpy as np 

def preprocess_data(data):
    """Permute the axis to make the channel the last one and scale.

    Args:
        data: [time, batch_size, channel, height, width]

    Returns:
        processed data of shape [time, batch_size, height, width, channel]
    """
    data = np.transpose(data, [0, 1, 3, 4, 2])
    #scale
    #data = np.divide(data, 255.0)
    #to normalize in range [-1, 1]
    data = 2 * data / 255 + (-1)
    return data

ROTATION = (-15, 15) 
test_total = 2000
seqlen = 16  
PATH = str(seqlen) + '-testdata'
mnt_generator = MovingMNISTAdvancedIterator(rotation_angle_range=ROTATION)
test_vid, _ = mnt_generator.sample(batch_size=test_total, seqlen=seqlen)
print(np.amax(test_vid))
print(np.amin(test_vid))
test_vid = preprocess_data(test_vid)
print(np.amax(test_vid))
print(np.amin(test_vid))
np.save(PATH, test_vid)
print(test_vid.shape)

The result is as follows:
424.88824
0.0
2.3324568
-1.0
(16, 2000, 64, 64, 1)
where you can see the maximum value is 424.88824.

Yes, the script will generate pixel values larger than 255. @gaozhihan has a fix for that.

you mean @gaozhihan has fixed it already or it's in progress? If it's done, could you tell me where to find it ? I have looked at his repositories, but nothing found.

I'm writing my master thesis which uses your MovingMINIST++ dataset. I would really appreciate it if you could post it earlier. Thank you!

I'm sorry that I didn't post it in this repo. Thanks for your comments. Please replace line 404 in movingmnist_iterator.py with (appearance_mult ** -(2 * (((i - 1) // 5) % 2) - 1))

I have noticed that line. But due to the use of modulo of 2, 2 * ((A // 5) % 2)) is either 0 or 2 no matter A is i or i - 1. So -(2 * ((A // 5) % 2) - 1) is either -1 or 1, which will make Term B larger than 1 when appearance_mult is less than 1. When Term B is larger than 1, then it's possible to have pixel value larger than 255.

Term B: (appearance_mult ** -(2 * (((i - 1) // 5) % 2) - 1))

But appearance_variants[i, :] won't be bigger than their initial values, since the loop starts with the maximum values

why won't appearance_variants[i, :] be bigger than their initial values?

appearance_variants[i, :] = appearance_variants[i - 1, :] *\
                                     (appearance_mult ** -(2 * (((i - 1) // 5) % 2) - 1))

In above code snippet, if (appearance_mult ** -(2 * (((i - 1) // 5) % 2) - 1)) is larger than 1, then it could be larger than initial values.

Besides after changing that line, I try to generate test dataset, the maximum value is still larger than 255 in some settings (seqlen, batch_size).

Because they first decrease and then return to the initial values. You may print the value of Term B out to check the change trend. In my experiment settings, the above mentioned problem does not appear anymore. If it still goes wrong, please simply clip the values that are larger than 255. It doesn't affect a lot since it is a synthetic dataset.

Thank you very much for your response especially on holiday. ☕