encoding and decoding pictures pytorch2019 Community Moderator ElectionUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)Model summary in pytorchTaking subsets of a pytorch datasetPyTorch Softmax Dimensions errorHow to initialize weights in PyTorch?Implementing a custom dataset with PyTorchEncoder Decoder Architecture in Pytorchcoverting roi pooling in pytorch to nn layerTrying to understand Pytorch neural translation code for decoderLSTM Encoder and Decoder architecture for specific case in Pytorch

Can "few" be used as a subject? If so, what is the rule?

What kind of footwear is suitable for walking in micro gravity environment?

"Marked down as someone wanting to sell shares." What does that mean?

Single word to change groups

Does fire aspect on a sword, destroy mob drops?

pipe commands inside find -exec?

Air travel with refrigerated insulin

The English Debate

UK Tourist Visa- Enquiry

Is a square zero matrix positive semidefinite?

Error in master's thesis, I do not know what to do

What is the difference between something being completely legal and being completely decriminalized?

How are passwords stolen from companies if they only store hashes?

is this saw blade faulty?

Jem'Hadar, something strange about their life expectancy

What are rules for concealing thieves tools (or items in general)?

What is the reasoning behind standardization (dividing by standard deviation)?

Is there any common country to visit for uk and schengen visa?

Do I need an EFI partition for each 18.04 ubuntu I have on my HD?

Should a narrator ever describe things based on a characters view instead of fact?

What is the tangent at a sharp point on a curve?

Friend wants my recommendation but I don't want to

Unfrosted light bulb

Why is "la Gestapo" feminine?



encoding and decoding pictures pytorch



2019 Community Moderator ElectionUnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)Model summary in pytorchTaking subsets of a pytorch datasetPyTorch Softmax Dimensions errorHow to initialize weights in PyTorch?Implementing a custom dataset with PyTorchEncoder Decoder Architecture in Pytorchcoverting roi pooling in pytorch to nn layerTrying to understand Pytorch neural translation code for decoderLSTM Encoder and Decoder architecture for specific case in Pytorch










1















Task: Using the example of the "fetch_lfw_people" dataset to write and train an autocoder.
Write an iteration code by epoch. Write code to visualize the learning process and count the metrics for validation after each epoch.
Train auto encoder. Achieve low loss on validation.



My code:



from sklearn.datasets import fetch_lfw_people
import numpy as np
import torch
from torch.utils.data import TensorDataset, DataLoader
from sklearn.model_selection import train_test_split


Data preparation:



lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4) 
X = lfw_people['images']

X_train, X_test = train_test_split(X, test_size=0.1)

X_train = torch.tensor(X_train, dtype=torch.float32, requires_grad=True)
X_test = torch.tensor(X_test, dtype=torch.float32, requires_grad=False)
dataset_train = TensorDataset(X_train, torch.zeros(len(X_train)))
dataset_test = TensorDataset(X_test, torch.zeros(len(X_test)))

batch_size = 32

train_loader = DataLoader(dataset_train, batch_size=batch_size, shuffle=True)
test_loader = DataLoader(dataset_test, batch_size=batch_size, shuffle=False)


Сreate a network with encoding and decoding functions:



class Autoencoder(torch.nn.Module): 
def __init__(self):
super(Autoencoder, self).__init__()
self.encoder = torch.nn.Sequential(
torch.nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=2),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=32, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3)
)

self.decoder = torch.nn.Sequential(
torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=3, stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=(3,4), stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=32, kernel_size=4, stride=2),

torch.nn.ConvTranspose2d(in_channels=32, out_channels=1, kernel_size=(4,3), stride=2)
)

def encode(self, X):
encoded_X = self.encoder(X)
batch_size = X.shape[0]
return encoded_X.reshape(batch_size, -1)

def decode(self, X):
pre_decoder = X.reshape(-1, 64, 2, 1)
return self.decoder(pre_decoder)


I check the work of the model before learning by one example:



model = Autoencoder()

sample = X_test[:1]
sample = sample[:, None]
result = model.decode(model.encode(sample)) # before train

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(result[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


The result is unsatisfactory. I start training:



model = Autoencoder()
loss = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

history_train = []
history_test = []

for i in range(5):
for x, y in train_loader:
x = x[:, None]

model.train()

decoded_x = model.decode(model.encode(x))
mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)

optimizer.zero_grad()
mse_loss.backward()
optimizer.step()

history_train.append(mse_loss.detach().numpy())

model.eval()
with torch.no_grad():
for x, y in train_loader:
x = x[:, None]

result_x = model.decode(model.encode(x))
loss_test = loss(torch.tensor(result_x, dtype=torch.float), x)

history_test.append(loss_test.detach().numpy())

plt.subplot(1, 2, 1)
plt.plot(history_train)
plt.title("Optimization process for train data")

plt.subplot(1, 2, 2)
plt.plot(history_test)
plt.title("Loss for test data")

plt.show


A huge loss on the training data and on the test.



Аfter training nothing has changed:



with torch.no_grad():
model.eval()
res1 = model.decode(model.encode(sample))

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(res1[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


Why such a big loss? Reducing the input to the interval [-1, 1] does not help. I did it like this: (value / 255) * 2 - 1
Why do not change the parameters of the model after training?
Why does not change the decoded sample?



Result: before train, after train, loss
https://i.stack.imgur.com/OhdrJ.jpg










share|improve this question
























  • What's the exact point of including a bunch of plot commands without showing their results?

    – desertnaut
    Mar 7 at 0:06











  • Thanks! Results added.

    – TGorlenko
    Mar 7 at 9:38















1















Task: Using the example of the "fetch_lfw_people" dataset to write and train an autocoder.
Write an iteration code by epoch. Write code to visualize the learning process and count the metrics for validation after each epoch.
Train auto encoder. Achieve low loss on validation.



My code:



from sklearn.datasets import fetch_lfw_people
import numpy as np
import torch
from torch.utils.data import TensorDataset, DataLoader
from sklearn.model_selection import train_test_split


Data preparation:



lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4) 
X = lfw_people['images']

X_train, X_test = train_test_split(X, test_size=0.1)

X_train = torch.tensor(X_train, dtype=torch.float32, requires_grad=True)
X_test = torch.tensor(X_test, dtype=torch.float32, requires_grad=False)
dataset_train = TensorDataset(X_train, torch.zeros(len(X_train)))
dataset_test = TensorDataset(X_test, torch.zeros(len(X_test)))

batch_size = 32

train_loader = DataLoader(dataset_train, batch_size=batch_size, shuffle=True)
test_loader = DataLoader(dataset_test, batch_size=batch_size, shuffle=False)


Сreate a network with encoding and decoding functions:



class Autoencoder(torch.nn.Module): 
def __init__(self):
super(Autoencoder, self).__init__()
self.encoder = torch.nn.Sequential(
torch.nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=2),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=32, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3)
)

self.decoder = torch.nn.Sequential(
torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=3, stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=(3,4), stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=32, kernel_size=4, stride=2),

torch.nn.ConvTranspose2d(in_channels=32, out_channels=1, kernel_size=(4,3), stride=2)
)

def encode(self, X):
encoded_X = self.encoder(X)
batch_size = X.shape[0]
return encoded_X.reshape(batch_size, -1)

def decode(self, X):
pre_decoder = X.reshape(-1, 64, 2, 1)
return self.decoder(pre_decoder)


I check the work of the model before learning by one example:



model = Autoencoder()

sample = X_test[:1]
sample = sample[:, None]
result = model.decode(model.encode(sample)) # before train

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(result[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


The result is unsatisfactory. I start training:



model = Autoencoder()
loss = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

history_train = []
history_test = []

for i in range(5):
for x, y in train_loader:
x = x[:, None]

model.train()

decoded_x = model.decode(model.encode(x))
mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)

optimizer.zero_grad()
mse_loss.backward()
optimizer.step()

history_train.append(mse_loss.detach().numpy())

model.eval()
with torch.no_grad():
for x, y in train_loader:
x = x[:, None]

result_x = model.decode(model.encode(x))
loss_test = loss(torch.tensor(result_x, dtype=torch.float), x)

history_test.append(loss_test.detach().numpy())

plt.subplot(1, 2, 1)
plt.plot(history_train)
plt.title("Optimization process for train data")

plt.subplot(1, 2, 2)
plt.plot(history_test)
plt.title("Loss for test data")

plt.show


A huge loss on the training data and on the test.



Аfter training nothing has changed:



with torch.no_grad():
model.eval()
res1 = model.decode(model.encode(sample))

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(res1[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


Why such a big loss? Reducing the input to the interval [-1, 1] does not help. I did it like this: (value / 255) * 2 - 1
Why do not change the parameters of the model after training?
Why does not change the decoded sample?



Result: before train, after train, loss
https://i.stack.imgur.com/OhdrJ.jpg










share|improve this question
























  • What's the exact point of including a bunch of plot commands without showing their results?

    – desertnaut
    Mar 7 at 0:06











  • Thanks! Results added.

    – TGorlenko
    Mar 7 at 9:38













1












1








1








Task: Using the example of the "fetch_lfw_people" dataset to write and train an autocoder.
Write an iteration code by epoch. Write code to visualize the learning process and count the metrics for validation after each epoch.
Train auto encoder. Achieve low loss on validation.



My code:



from sklearn.datasets import fetch_lfw_people
import numpy as np
import torch
from torch.utils.data import TensorDataset, DataLoader
from sklearn.model_selection import train_test_split


Data preparation:



lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4) 
X = lfw_people['images']

X_train, X_test = train_test_split(X, test_size=0.1)

X_train = torch.tensor(X_train, dtype=torch.float32, requires_grad=True)
X_test = torch.tensor(X_test, dtype=torch.float32, requires_grad=False)
dataset_train = TensorDataset(X_train, torch.zeros(len(X_train)))
dataset_test = TensorDataset(X_test, torch.zeros(len(X_test)))

batch_size = 32

train_loader = DataLoader(dataset_train, batch_size=batch_size, shuffle=True)
test_loader = DataLoader(dataset_test, batch_size=batch_size, shuffle=False)


Сreate a network with encoding and decoding functions:



class Autoencoder(torch.nn.Module): 
def __init__(self):
super(Autoencoder, self).__init__()
self.encoder = torch.nn.Sequential(
torch.nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=2),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=32, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3)
)

self.decoder = torch.nn.Sequential(
torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=3, stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=(3,4), stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=32, kernel_size=4, stride=2),

torch.nn.ConvTranspose2d(in_channels=32, out_channels=1, kernel_size=(4,3), stride=2)
)

def encode(self, X):
encoded_X = self.encoder(X)
batch_size = X.shape[0]
return encoded_X.reshape(batch_size, -1)

def decode(self, X):
pre_decoder = X.reshape(-1, 64, 2, 1)
return self.decoder(pre_decoder)


I check the work of the model before learning by one example:



model = Autoencoder()

sample = X_test[:1]
sample = sample[:, None]
result = model.decode(model.encode(sample)) # before train

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(result[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


The result is unsatisfactory. I start training:



model = Autoencoder()
loss = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

history_train = []
history_test = []

for i in range(5):
for x, y in train_loader:
x = x[:, None]

model.train()

decoded_x = model.decode(model.encode(x))
mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)

optimizer.zero_grad()
mse_loss.backward()
optimizer.step()

history_train.append(mse_loss.detach().numpy())

model.eval()
with torch.no_grad():
for x, y in train_loader:
x = x[:, None]

result_x = model.decode(model.encode(x))
loss_test = loss(torch.tensor(result_x, dtype=torch.float), x)

history_test.append(loss_test.detach().numpy())

plt.subplot(1, 2, 1)
plt.plot(history_train)
plt.title("Optimization process for train data")

plt.subplot(1, 2, 2)
plt.plot(history_test)
plt.title("Loss for test data")

plt.show


A huge loss on the training data and on the test.



Аfter training nothing has changed:



with torch.no_grad():
model.eval()
res1 = model.decode(model.encode(sample))

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(res1[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


Why such a big loss? Reducing the input to the interval [-1, 1] does not help. I did it like this: (value / 255) * 2 - 1
Why do not change the parameters of the model after training?
Why does not change the decoded sample?



Result: before train, after train, loss
https://i.stack.imgur.com/OhdrJ.jpg










share|improve this question
















Task: Using the example of the "fetch_lfw_people" dataset to write and train an autocoder.
Write an iteration code by epoch. Write code to visualize the learning process and count the metrics for validation after each epoch.
Train auto encoder. Achieve low loss on validation.



My code:



from sklearn.datasets import fetch_lfw_people
import numpy as np
import torch
from torch.utils.data import TensorDataset, DataLoader
from sklearn.model_selection import train_test_split


Data preparation:



lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4) 
X = lfw_people['images']

X_train, X_test = train_test_split(X, test_size=0.1)

X_train = torch.tensor(X_train, dtype=torch.float32, requires_grad=True)
X_test = torch.tensor(X_test, dtype=torch.float32, requires_grad=False)
dataset_train = TensorDataset(X_train, torch.zeros(len(X_train)))
dataset_test = TensorDataset(X_test, torch.zeros(len(X_test)))

batch_size = 32

train_loader = DataLoader(dataset_train, batch_size=batch_size, shuffle=True)
test_loader = DataLoader(dataset_test, batch_size=batch_size, shuffle=False)


Сreate a network with encoding and decoding functions:



class Autoencoder(torch.nn.Module): 
def __init__(self):
super(Autoencoder, self).__init__()
self.encoder = torch.nn.Sequential(
torch.nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=2),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=32, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3),
torch.nn.ReLU(),

torch.nn.Conv2d(in_channels=64, out_channels=64, stride=2, kernel_size=3)
)

self.decoder = torch.nn.Sequential(
torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=3, stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=64, kernel_size=(3,4), stride=2),

torch.nn.ConvTranspose2d(in_channels=64, out_channels=32, kernel_size=4, stride=2),

torch.nn.ConvTranspose2d(in_channels=32, out_channels=1, kernel_size=(4,3), stride=2)
)

def encode(self, X):
encoded_X = self.encoder(X)
batch_size = X.shape[0]
return encoded_X.reshape(batch_size, -1)

def decode(self, X):
pre_decoder = X.reshape(-1, 64, 2, 1)
return self.decoder(pre_decoder)


I check the work of the model before learning by one example:



model = Autoencoder()

sample = X_test[:1]
sample = sample[:, None]
result = model.decode(model.encode(sample)) # before train

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(result[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


The result is unsatisfactory. I start training:



model = Autoencoder()
loss = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

history_train = []
history_test = []

for i in range(5):
for x, y in train_loader:
x = x[:, None]

model.train()

decoded_x = model.decode(model.encode(x))
mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)

optimizer.zero_grad()
mse_loss.backward()
optimizer.step()

history_train.append(mse_loss.detach().numpy())

model.eval()
with torch.no_grad():
for x, y in train_loader:
x = x[:, None]

result_x = model.decode(model.encode(x))
loss_test = loss(torch.tensor(result_x, dtype=torch.float), x)

history_test.append(loss_test.detach().numpy())

plt.subplot(1, 2, 1)
plt.plot(history_train)
plt.title("Optimization process for train data")

plt.subplot(1, 2, 2)
plt.plot(history_test)
plt.title("Loss for test data")

plt.show


A huge loss on the training data and on the test.



Аfter training nothing has changed:



with torch.no_grad():
model.eval()
res1 = model.decode(model.encode(sample))

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
ax1.imshow(sample[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
ax2.imshow(res1[0][0].detach().numpy(), cmap=plt.cm.Greys_r)
plt.show()


Why such a big loss? Reducing the input to the interval [-1, 1] does not help. I did it like this: (value / 255) * 2 - 1
Why do not change the parameters of the model after training?
Why does not change the decoded sample?



Result: before train, after train, loss
https://i.stack.imgur.com/OhdrJ.jpg







python machine-learning neural-network pytorch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 9:31







TGorlenko

















asked Mar 6 at 23:12









TGorlenkoTGorlenko

62




62












  • What's the exact point of including a bunch of plot commands without showing their results?

    – desertnaut
    Mar 7 at 0:06











  • Thanks! Results added.

    – TGorlenko
    Mar 7 at 9:38

















  • What's the exact point of including a bunch of plot commands without showing their results?

    – desertnaut
    Mar 7 at 0:06











  • Thanks! Results added.

    – TGorlenko
    Mar 7 at 9:38
















What's the exact point of including a bunch of plot commands without showing their results?

– desertnaut
Mar 7 at 0:06





What's the exact point of including a bunch of plot commands without showing their results?

– desertnaut
Mar 7 at 0:06













Thanks! Results added.

– TGorlenko
Mar 7 at 9:38





Thanks! Results added.

– TGorlenko
Mar 7 at 9:38












1 Answer
1






active

oldest

votes


















0














1) replace line



mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)


with line



mse_loss = loss(decoded_x, x)


2) replace lines



model.eval()
with torch.no_grad():
for x, y in train_loader:


with lines



replace lines



model.eval()
with torch.no_grad():
for x, y in test_loader:





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033669%2fencoding-and-decoding-pictures-pytorch%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    1) replace line



    mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)


    with line



    mse_loss = loss(decoded_x, x)


    2) replace lines



    model.eval()
    with torch.no_grad():
    for x, y in train_loader:


    with lines



    replace lines



    model.eval()
    with torch.no_grad():
    for x, y in test_loader:





    share|improve this answer



























      0














      1) replace line



      mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)


      with line



      mse_loss = loss(decoded_x, x)


      2) replace lines



      model.eval()
      with torch.no_grad():
      for x, y in train_loader:


      with lines



      replace lines



      model.eval()
      with torch.no_grad():
      for x, y in test_loader:





      share|improve this answer

























        0












        0








        0







        1) replace line



        mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)


        with line



        mse_loss = loss(decoded_x, x)


        2) replace lines



        model.eval()
        with torch.no_grad():
        for x, y in train_loader:


        with lines



        replace lines



        model.eval()
        with torch.no_grad():
        for x, y in test_loader:





        share|improve this answer













        1) replace line



        mse_loss = loss(torch.tensor(decoded_x, dtype=torch.float), x)


        with line



        mse_loss = loss(decoded_x, x)


        2) replace lines



        model.eval()
        with torch.no_grad():
        for x, y in train_loader:


        with lines



        replace lines



        model.eval()
        with torch.no_grad():
        for x, y in test_loader:






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 10 at 11:07









        TGorlenkoTGorlenko

        62




        62





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033669%2fencoding-and-decoding-pictures-pytorch%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович