Max value for contrast in pythorch transform

username: nafise
cooked: <p>Hi,<br>
What is the maximum value for contrast in transformation?</p>

username: ptrblck
cooked: <p>Based on the <a href="https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.functional.adjust_contrast">docs</a> for <code>transforms.functional.adjust_contrast</code>:</p>
<blockquote>
<ul>
<li><strong>contrast_factor</strong> (<a href="https://docs.python.org/3/library/functions.html#float"><em>float</em></a>) – How much to adjust the contrast. Can be any non negative number. 0 gives a solid gray image, 1 gives the original image while 2 increases the contrast by a factor of 2.</li>
</ul>
</blockquote>

username: nafise
cooked: <p>Hi, thanks for response <img src="https://discuss.pytorch.org/images/emoji/apple/pray.png?v=9" title=":pray:" class="emoji" alt=":pray:"> <img src="https://discuss.pytorch.org/images/emoji/apple/pray.png?v=9" title=":pray:" class="emoji" alt=":pray:"><br>
I have a cnn for color image classification, the accuracy of the model was very low, after changing the contrast, the accuracy improved.<br>
The values I considered for colorjitter include:<br>
transforms.ColorJitter(brightness=(1.5), contrast=(0.9), saturation=(1.5), hue=(-0.1,0.1))<br>
I want to know the values must be between 0 and 1 ?<br>
Are the values I considered correct?<br>
I do not understand the interpretation of the original document.Thanks, guide me.</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="nafise" data-post="3" data-topic="116489">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/n/76d3ee/48.png" class="avatar"> nafise:</div>
<blockquote>
<p>I want to know the values must be between 0 and 1 ?</p>
</blockquote>
</aside>
<p>No, the values can be in the range <code>[0, +Inf]</code> (of course a very high positive value would distort the image at one point).<br>
To lower the contrast, use values in <code>[0, 1]</code>, to increase it use values <code>&gt;1</code>.</p>

username: nafise
cooked: <h2>Thanks.<br>
I have another problem, when I execute the code with validation data, at the end of the first epoch, this error ends.<br>
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:166: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.<br>
Epoch [1/10], Step [50/220], Loss: 0.6466<br>
Epoch [1/10], Step [100/220], Loss: 0.6466<br>
Epoch [1/10], Step [150/220], Loss: 0.5845<br>
Epoch [1/10], Step [200/220], Loss: 1.0444</h2>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in ()<br>
21<br>
22         # forward pass<br>
—&gt; 23         outputs = model(images)<br>
24         loss = criterion(outputs, labels)<br>
25</p>
<p>1 frames<br>
 in forward(self, x)<br>
173     # print(main_out.shape)<br>
174     # print(Attentiom_map.shape)<br>
 → 175     out1 = torch.matmul(main_out, Attentiom_map)<br>
176     max_pool1 = self.pool(torch.add(main_out, out1))<br>
177     # print(max_pool1.shape)</p>
<p>RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 0</p>

username: ptrblck
cooked: <p>Based on the error message it seems that <code>main_out</code> and <code>Attentiom_map</code> have shapes, which are incompatible for the <code>torch.matmul</code> operation.<br>
In your code you’ve already added the print statements for the shapes, so you could (re-)use it and make sure both tensors have the expected shape.<br>
Here is a small example of your error:</p>
<pre><code class="lang-python"># works
a, b = torch.randn(2, 10, 20), torch.randn(2, 20, 10)
c = torch.matmul(a, b)

# raises your error
a, b = torch.randn(2, 10, 20), torch.randn(3, 20, 10)
c = torch.matmul(a, b)
&gt; RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 0
</code></pre>

username: nafise
cooked: <p>yes, I printed the tensors, In one of the steps, the first parameter(batch) becomes 2? But I do not know why this happens.</p>

username: nafise
cooked: <p>I made them  the same size, but in the last step, when main_out  batch equals 2, Attentiom_map batch 3 remains.<br>
But I do not know how to resize them</p>

username: nafise
cooked: <h2>torch.Size([3, 64, 349, 349])<br>
torch.Size([3, 64, 199, 349])<br>
torch.Size([3, 64, 349, 349])<br>
torch.Size([3, 64, 199, 349])<br>
torch.Size([3, 64, 349, 349])<br>
torch.Size([2, 64, 199, 349])<br>
torch.Size([3, 64, 349, 349])</h2>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in ()<br>
21<br>
22         # forward pass<br>
—&gt; 23         outputs = model(images)<br>
24         loss = criterion(outputs, labels)<br>
25</p>
<p>1 frames<br>
 in forward(self, x)<br>
173     print(main_out.shape)<br>
174     print(Attentiom_map.shape)<br>
 → 175     out1 = torch.matmul(main_out, Attentiom_map)<br>
176     max_pool1 = self.pool(torch.add(main_out, out1))<br>
177     # print(max_pool1.shape)</p>
<p>RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 0</p>
<p>main_out = self.pool1(F.relu(self.conv(x)))<br>
Attentiom_map = Attentiom_map.repeat(3, 64, 1, 1)<br>
Attentiom_map = F.interpolate(Attentiom_map, size=(main_out.data[0].shape[2], main_out.data[0].shape[2]), mode=‘bilinear’, align_corners=False)<br>
out1 = torch.matmul(main_out, Attentiom_map)</p>