Preprocessing float data CSVs for evaluation using Resnet

GreatScherzo: <p>Hi! I’m currently working on evaluating float32 data in CSVs using Wide-Resnet.</p>
<h2><a name="data-explanation-1" class="anchor" href="#data-explanation-1"></a>Data Explanation</h2>
<p>The CSV data also have nan values within them (which is represented with “-”). The data doesn’t have any specific min or max range to them, unlike byte images, where the range is 0-255.<br>
Here’s 2 snippets of a part of the data.</p>
<p><a href="https://i.stack.imgur.com/4GQy1.png" rel="noopener nofollow ugc"><img src="https://i.stack.imgur.com/4GQy1.png" alt="enter image description here" width="435" height="377"></a></p>
<p><a href="https://i.stack.imgur.com/1HEou.png" rel="noopener nofollow ugc"><img src="https://i.stack.imgur.com/1HEou.png" alt="enter image description here" width="508" height="451"></a></p>
<h2><a name="preprocessing-explanation-2" class="anchor" href="#preprocessing-explanation-2"></a>Preprocessing Explanation</h2>
<p>I evaluated the data by reading them to a dataframe using pandas library, and converted the “-” to nan value. I then converted the dataframe to a PIL float image and preprocessed it using torchvision.<br>
The code below shows the preprocess used.</p>
<h4><a name="preprocessing-code-3" class="anchor" href="#preprocessing-code-3"></a>Preprocessing Code</h4>
<blockquote>
<pre><code>def __getitem__(self, idx):
    # get path of csv file
    x = self.x[idx]

    # convert csv to dataframe
    x = pd.read_csv(x, delimiter=',', skiprows=5, na_values="-", dtype=np.float32)

    warnings.filterwarnings("ignore")
    x1 = x.to_numpy()

    # convert to image and apply resize and other preprocess
    x2 = self.transform_x(x1)

    # pre-normalization
    scaler = MinMaxScaler()
    x3 = scaler.fit_transform(x2)

    # replacing nan with lowest value
    x3[np.isnan(x3)] = 0
    warnings.filterwarnings("default")

    # Create a fake 3 channel tensor by copying and stacking the data
    x4 = T.ToTensor()(np.array(x3))
    x5 = torch.cat([x4, x4, x4], dim=0)

    x6 = T.Normalize(self.ImageNetNormParam["mean"],
                     self.ImageNetNormParam["std"],)(x5)

    # Tensor type seems to change to double along the way, so it
    # is once again reconverted to float
    x7 = x6.to(dtype=torch.float)

    # it turns to a tensor and returned
    return x7, y
</code></pre>
</blockquote>
<blockquote>
<pre><code>    self.ImageNetNormParam = {"mean": [0.485, 0.456, 0.406],
                              "std": [0.229, 0.224, 0.225]
                              }
    self.resize = (416, 288)

    self.transform_x = T.Compose([T.ToPILImage(),
                                  T.Resize(resize, Image.ANTIALIAS),
                                  ])
</code></pre>
</blockquote>
<h2><a name="problem-statement-4" class="anchor" href="#problem-statement-4"></a>Problem Statement</h2>
<p>My questions are as below:</p>
<h4><a name="h-1-5" class="anchor" href="#h-1-5"></a>1</h4>
<p>In my preprocessing, I copied and stacked my 1 channel tensor to create a fake 3 channel tensor so that Resnet could read it.<br>
Is it OK to do this? Is there a more correct way to evaluate 1chn data using Resnet? Are there pretrained architectures where it accepts 1 channel data?</p>
<h4><a name="h-2-6" class="anchor" href="#h-2-6"></a>2</h4>
<p>In my preprocessing, I replaced the nan value in the data with 0. However, this will overlap with actual 0 values existing within my data.<br>
Is there a way to mask nan data such as that Resnet would read this data as not-effective values, or are there other ways to approach this?</p>
<h4><a name="h-3-7" class="anchor" href="#h-3-7"></a>3</h4>
<p>My normalization used Imagenets’s stdev and men preset to normalize. However, my type of data isn’t the same such as the ones in Imagenet. Is that OK, or should I calculate my own stdev and mean based on my data?</p>
<h4><a name="h-4-8" class="anchor" href="#h-4-8"></a>4</h4>
<p>I used scikit-learn’s min max scaler to scale my data to 0-1. However, I would like so that my data wouldn’t be scale based on each individual data’s min and max, but with the min and max that is based of all the data. This is the same as scaling byte images, where every image has a determined min max which is 0-255.</p>
<p>However, problem arises when I evaluate multiple batches of these data. For example, supposedly for the 1st batch of float csv data, I get a min max of -5to3. I then used this as a standard and scaled the 1st batch and 2nd batch with the standard min max. But for the 3rd batch, the min was -50 and under the standard min. This would lead to an improper scaling of the 3rd batch.</p>
<p>Can Resnet still read the improperly scaled batch? Or is there a way to scale float CSVs (which doesn’t have any min max range) properly?</p>
<hr>
<p>Thank you very much for taking your time in answering my questions.</p>