Implemented batching for TicTacToe AI
This commit is contained in:
parent
55cff9b18f
commit
56ee2635b5
96 changed files with 8426 additions and 7 deletions
|
|
@ -0,0 +1,9 @@
|
|||
wandb_version: 1
|
||||
|
||||
_wandb:
|
||||
desc: null
|
||||
value:
|
||||
cli_version: 0.8.22
|
||||
framework: torch
|
||||
is_jupyter_run: false
|
||||
python_version: 3.7.5
|
||||
132
TicTacToe_AI/Net/wandb/run-20200128_101238-9s87yjpe/diff.patch
Normal file
132
TicTacToe_AI/Net/wandb/run-20200128_101238-9s87yjpe/diff.patch
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
diff --git a/TicTacToe_AI/Net/pytorch_ai.py b/TicTacToe_AI/Net/pytorch_ai.py
|
||||
index efea5ae..8990206 100644
|
||||
--- a/TicTacToe_AI/Net/pytorch_ai.py
|
||||
+++ b/TicTacToe_AI/Net/pytorch_ai.py
|
||||
@@ -4,6 +4,11 @@ import torch.optim as optim
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
from tqdm import tqdm
|
||||
+import wandb
|
||||
+
|
||||
+wandb.init(project="tictactoe")
|
||||
+
|
||||
+BATCH_SIZE = 150
|
||||
|
||||
|
||||
def to_set(raw_list):
|
||||
@@ -35,6 +40,40 @@ def to_set(raw_list):
|
||||
return out_set
|
||||
|
||||
|
||||
+def to_batched_set(raw_list):
|
||||
+ counter = 0
|
||||
+ out_set = []
|
||||
+ boardtensor = torch.zeros((BATCH_SIZE, 1, 9))
|
||||
+ labeltensor = torch.zeros(BATCH_SIZE)
|
||||
+ for line in tqdm(raw_list):
|
||||
+ line = line.replace('\n', '')
|
||||
+ raw_board, raw_label = line.split('|')[0], line.split('|')[1]
|
||||
+
|
||||
+ if not (int(raw_label) is -1):
|
||||
+ labeltensor[counter] = int(raw_label)
|
||||
+ else:
|
||||
+ labeltensor[counter] = 9
|
||||
+
|
||||
+ raw_board = raw_board.split(',')
|
||||
+ for n, block in enumerate(raw_board):
|
||||
+ if int(block) is -1:
|
||||
+ boardtensor[counter][0][n] = 0
|
||||
+ elif int(block) is 0:
|
||||
+ boardtensor[counter][0][n] = 0.5
|
||||
+ elif int(block) is 1:
|
||||
+ boardtensor[counter][0][n] = 1
|
||||
+
|
||||
+ if counter == (BATCH_SIZE - 1):
|
||||
+ out_set.append([boardtensor, labeltensor])
|
||||
+ boardtensor = torch.zeros((BATCH_SIZE, 1, 9))
|
||||
+ labeltensor = torch.zeros(BATCH_SIZE)
|
||||
+ counter = 0
|
||||
+ else:
|
||||
+ counter += 1
|
||||
+
|
||||
+ return out_set
|
||||
+
|
||||
+
|
||||
def buildsets():
|
||||
with open('boards.bds', 'r') as infile:
|
||||
print('Loading file...')
|
||||
@@ -43,10 +82,10 @@ def buildsets():
|
||||
random.shuffle(alllines)
|
||||
|
||||
print('Generating testset...')
|
||||
- testset = to_set(alllines[0:10000])
|
||||
+ testset = to_batched_set(alllines[0:10000])
|
||||
|
||||
print('Generating trainset...')
|
||||
- trainset = to_set(alllines[10001:200000])
|
||||
+ trainset = to_batched_set(alllines[10001:100000])
|
||||
|
||||
return trainset, testset
|
||||
|
||||
@@ -60,6 +99,7 @@ def testnet(net, testset):
|
||||
if torch.argmax(output) == label[0]:
|
||||
correct += 1
|
||||
total += 1
|
||||
+ wandb.log({'test_accuracy': correct / total})
|
||||
print("Accuracy: ", round(correct / total, 3))
|
||||
|
||||
|
||||
@@ -79,7 +119,15 @@ class Net(torch.nn.Module):
|
||||
return F.log_softmax(x, dim=1)
|
||||
|
||||
|
||||
-net = torch.load('./nets/net_3.pt')
|
||||
+device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
+print('running on %s' % device)
|
||||
+
|
||||
+# net = torch.load('./nets/net_3.pt')
|
||||
+
|
||||
+net = Net()
|
||||
+wandb.watch(net)
|
||||
+
|
||||
+net.to(device)
|
||||
|
||||
optimizer = optim.Adam(net.parameters(), lr=0.001)
|
||||
|
||||
@@ -87,13 +135,16 @@ trainset, testset = buildsets()
|
||||
|
||||
for epoch in range(100):
|
||||
print('Epoch: ' + str(epoch))
|
||||
+ wandb.log({'epoch': epoch})
|
||||
for X, label in tqdm(trainset):
|
||||
net.zero_grad()
|
||||
+ X.to(device)
|
||||
output = net(X)
|
||||
+ output.cpu()
|
||||
loss = F.nll_loss(output.view(1, 10), label[0])
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
+ wandb.log({'loss': loss})
|
||||
|
||||
- print(loss)
|
||||
- torch.save(net, './nets/net_' + str(epoch + 3) + '.pt')
|
||||
+ torch.save(net, './nets/gpunets/net_' + str(epoch) + '.pt')
|
||||
testnet(net, testset)
|
||||
diff --git a/other_scripts/setcounter.py b/other_scripts/setcounter.py
|
||||
index 9735f20..e9eb00c 100644
|
||||
--- a/other_scripts/setcounter.py
|
||||
+++ b/other_scripts/setcounter.py
|
||||
@@ -7,9 +7,12 @@ data = datasets.MNIST('../datasets', train=True, download=True,
|
||||
transforms.ToTensor()
|
||||
]))
|
||||
|
||||
-loader = torch.utils.data.DataLoader(data, batch_size=1, shuffle=False)
|
||||
+loader = torch.utils.data.DataLoader(data, batch_size=15, shuffle=False)
|
||||
set = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
|
||||
|
||||
+for data in loader:
|
||||
+ print(data[1].shape)
|
||||
+
|
||||
for _, label in tqdm(loader):
|
||||
set[str(label[0].item())] += 1
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,109 @@
|
|||
apturl==0.5.2
|
||||
argh==0.26.2
|
||||
asn1crypto==0.24.0
|
||||
bcrypt==3.1.6
|
||||
binwalk==2.1.2
|
||||
blinker==1.4
|
||||
brlapi==0.6.7
|
||||
certifi==2018.8.24
|
||||
chardet==3.0.4
|
||||
click==7.0
|
||||
command-not-found==0.3
|
||||
configparser==4.0.2
|
||||
cryptography==2.6.1
|
||||
cupshelpers==1.0
|
||||
cycler==0.10.0
|
||||
dbus-python==1.2.12
|
||||
decorator==4.3.0
|
||||
defer==1.0.6
|
||||
distro-info==0.21ubuntu4
|
||||
distro==1.3.0
|
||||
docker-pycreds==0.4.0
|
||||
duplicity==0.8.4
|
||||
entrypoints==0.3
|
||||
fasteners==0.12.0
|
||||
future==0.16.0
|
||||
gitdb2==2.0.6
|
||||
gitpython==3.0.5
|
||||
gql==0.2.0
|
||||
graphql-core==1.1
|
||||
httplib2==0.11.3
|
||||
idna==2.6
|
||||
keyring==18.0.1
|
||||
keyrings.alt==3.1.1
|
||||
kiwisolver==1.0.1
|
||||
language-selector==0.1
|
||||
launchpadlib==1.10.7
|
||||
lazr.restfulclient==0.14.2
|
||||
lazr.uri==1.0.3
|
||||
lockfile==0.12.2
|
||||
louis==3.10.0
|
||||
macaroonbakery==1.2.3
|
||||
mako==1.0.7
|
||||
markupsafe==1.1.0
|
||||
matplotlib==3.0.2
|
||||
monotonic==1.5
|
||||
netifaces==0.10.4
|
||||
numpy==1.16.2
|
||||
nvidia-ml-py3==7.352.0
|
||||
oauth==1.0.1
|
||||
oauthlib==2.1.0
|
||||
olefile==0.46
|
||||
paramiko==2.6.0
|
||||
pathtools==0.1.2
|
||||
pexpect==4.6.0
|
||||
pillow==6.1.0
|
||||
pip==18.1
|
||||
promise==2.3
|
||||
protobuf==3.6.1
|
||||
psutil==5.6.7
|
||||
pycairo==1.16.2
|
||||
pycrypto==2.6.1
|
||||
pycups==1.9.73
|
||||
pygments==2.3.1
|
||||
pygobject==3.34.0
|
||||
pyjwt==1.7.0
|
||||
pymacaroons==0.13.0
|
||||
pynacl==1.3.0
|
||||
pyopengl==3.1.0
|
||||
pyparsing==2.2.0
|
||||
pyqt5==5.12.3
|
||||
pyqtgraph==0.11.0.dev0
|
||||
pyrfc3339==1.1
|
||||
python-apt==1.9.0+ubuntu1.3
|
||||
python-dateutil==2.7.3
|
||||
python-debian==0.1.36
|
||||
pytz==2019.2
|
||||
pyxdg==0.25
|
||||
pyyaml==5.1.2
|
||||
reportlab==3.5.23
|
||||
requests-unixsocket==0.1.5
|
||||
requests==2.21.0
|
||||
scipy==1.2.2
|
||||
secretstorage==2.3.1
|
||||
sentry-sdk==0.14.0
|
||||
setuptools==41.1.0
|
||||
shortuuid==0.5.0
|
||||
simplejson==3.16.0
|
||||
sip==4.19.18
|
||||
six==1.12.0
|
||||
smmap2==2.0.5
|
||||
subprocess32==3.5.4
|
||||
system-service==0.3
|
||||
systemd-python==234
|
||||
torch==1.3.1+cpu
|
||||
torchvision==0.4.2+cpu
|
||||
tqdm==4.41.0
|
||||
ubuntu-advantage-tools==19.5
|
||||
ubuntu-drivers-common==0.0.0
|
||||
ufw==0.36
|
||||
unattended-upgrades==0.1
|
||||
urllib3==1.24.1
|
||||
usb-creator==0.3.7
|
||||
virtualenv==15.1.0
|
||||
wadllib==1.3.3
|
||||
wandb==0.8.22
|
||||
watchdog==0.9.0
|
||||
wheel==0.32.3
|
||||
xkit==0.0.0
|
||||
zope.interface==4.3.2
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
{"system.cpu": 84.36, "system.memory": 49.44, "system.disk": 8.1, "system.proc.memory.availableMB": 3895.05, "system.proc.memory.rssMB": 191.12, "system.proc.memory.percent": 2.48, "system.proc.cpu.threads": 1.87, "system.network.sent": 109502, "system.network.recv": 249550, "_wandb": true, "_timestamp": 1580206387, "_runtime": 29}
|
||||
{"system.cpu": 67.12, "system.memory": 48.28, "system.disk": 8.1, "system.proc.memory.availableMB": 3982.67, "system.proc.memory.rssMB": 166.54, "system.proc.memory.percent": 2.16, "system.proc.cpu.threads": 1.8, "system.network.sent": 132366, "system.network.recv": 276842, "_wandb": true, "_timestamp": 1580206395, "_runtime": 37}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"epoch": 0, "_runtime": 38.271220684051514, "_timestamp": 1580206395.6194339, "_step": 0}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"root": "/home/clemens/repositorys/pytorch-ai",
|
||||
"program": "pytorch_ai.py",
|
||||
"git": {
|
||||
"remote": "git@github.com:Clemens-Dautermann/pytorch-ai.git",
|
||||
"commit": "55cff9b18f8558ae7a9170e56a3d5c6f6665d9ab"
|
||||
},
|
||||
"email": "clemens.dautermann@gmail.com",
|
||||
"startedAt": "2020-01-28T10:12:38.459566",
|
||||
"host": "ubuntu-laptop",
|
||||
"username": "clemens",
|
||||
"executable": "/usr/bin/python3",
|
||||
"os": "Linux-5.3.0-26-generic-x86_64-with-Ubuntu-19.10-eoan",
|
||||
"python": "3.7.5",
|
||||
"cpu_count": 2,
|
||||
"args": [],
|
||||
"state": "failed",
|
||||
"jobType": null,
|
||||
"mode": "run",
|
||||
"project": "tictactoe",
|
||||
"heartbeatAt": "2020-01-28T10:13:16.492404",
|
||||
"exitcode": 1
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"_runtime": 38.271220684051514, "_timestamp": 1580206395.6194339, "epoch": 0, "_step": 0}
|
||||
Loading…
Add table
Add a link
Reference in a new issue