Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #Не работает
  2. def tryer(i):
  3. body = []
  4. header = [nn.Linear(len(feature_columns), 100),
  5. nn.ReLU(),
  6. nn.Dropout(p=0.5)]
  7. tail = [
  8. nn.Linear(100, 3)]
  9. for _ in range(i):
  10. body += [
  11. nn.Linear(100, 100),
  12. nn.ReLU(),
  13. nn.BatchNorm1d(100)]
  14.  
  15. K = [*header, *body, *tail]
  16. model = nn.Sequential(*K)
  17. loss_fn = torch.nn.CrossEntropyLoss()
  18. optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
  19. train_losses, test_losses = train(20)
  20. plt.plot(train_losses)
  21. plt.show()
  22. m = min(train_losses)
  23. return [m, i]
  24.  
  25. mi = []
  26. it = []
  27. for i in range(5):
  28. torch.manual_seed(42)
  29. np.random.seed(42)
  30. if(i == 0):
  31. continue
  32. T = tryer(i)
  33. mi.append(T[0])
  34. it.append(T[1])
  35. plt.plot(mi)
  36.  
  37. #Работает
  38.  
  39. mi = []
  40. for i in range(10):
  41. torch.manual_seed(42)
  42. np.random.seed(42)
  43. body = []
  44. header = [nn.Linear(len(feature_columns), 100),
  45. nn.ReLU(),
  46. nn.Dropout(p=0.5)]
  47. tail = [
  48. nn.Linear(100, 3)]
  49. for _ in range(i):
  50. body += [
  51. nn.Linear(100, 100),
  52. nn.ReLU(),
  53. nn.BatchNorm1d(100)]
  54.  
  55. K = [*header, *body, *tail]
  56. model = nn.Sequential(*K)
  57. loss_fn = torch.nn.CrossEntropyLoss()
  58. optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
  59. train_losses, test_losses = train(20)
  60. m = min(train_losses)
  61. mi.append(m)
  62. plt.plot(train_losses)
  63. plt.show()
  64. plt.plot(mi)
  65. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement