'Failed to use transforms.ToTensor and transforms.Normalize to normalize the MNIST dataset
I used the following code to normalize the MNIST dataset, when I print the first sample, it fails to normalize as the max element is 255, not 1.
train_transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))])
train_set = torchvision.datasets.MNIST(
root=data_dir, train=True, download=True, transform=train_transform)
When I check the range of the dataset input images:
print("min:%f max:%f" %(train_set.data.min(), train_set.data.max()))
output result:min:0.000000 max:255.000000
I was expecting [0, 1] instead, I don't know why that is. Is there something wrong?
Solution 1:[1]
You can use those options then
const element = await page.$$("text='element'");
if (element) {
// ...
}
or
const element = await page.$$("text='element'");
if (element.length) {
// ...
}
or
await expect(page.locator(".MyClass")).toHaveCount(0)
Solution 2:[2]
You have several options depending on particular needs; If your element is not hidden you can use:
page.locator("your_locator").isVisible();
If it is hidden you can try with.
try{
page.waitForSelector("your_locator",{timeout:5000});}
catch(){
//element is not found do next
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | LSeu |
| Solution 2 | Gaj Julije |
