going to pytorch on conda eve

This commit is contained in:
shaaqu 2020-05-26 00:55:12 +02:00
parent 239eaf7d97
commit 4720da3158
25 changed files with 103 additions and 47 deletions

View File

@ -3,5 +3,5 @@
<component name="JavaScriptSettings"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (AL-2020)" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -20,9 +20,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="828778c9-9d97-422f-a727-18ddbd059b85" name="Default Changelist" comment="po"> <list default="true" id="828778c9-9d97-422f-a727-18ddbd059b85" name="Default Changelist" comment="po">
<change afterPath="$PROJECT_DIR$/coder/dataset/test.csv" afterDir="false" /> <change afterPath="$PROJECT_DIR$/coder/digits_recognizer.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/coder/dataset/train.csv" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/wozek.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/wozek.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/coder/image.py" beforeDir="false" afterPath="$PROJECT_DIR$/coder/image.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/coder/image.py" beforeDir="false" afterPath="$PROJECT_DIR$/coder/image.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -82,7 +83,7 @@
<recent name="C:\Users\Pawel Lukaszewicz\PycharmProjects\AL-2020\coder" /> <recent name="C:\Users\Pawel Lukaszewicz\PycharmProjects\AL-2020\coder" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Python.image"> <component name="RunManager" selected="Python.digits_recognizer">
<configuration default="true" type="PythonConfigurationType" factoryName="Python"> <configuration default="true" type="PythonConfigurationType" factoryName="Python">
<module name="wozek" /> <module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -105,22 +106,19 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="feature_hashing" type="PythonConfigurationType" factoryName="Python" temporary="true"> <configuration name="digits_recognizer" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="wozek" /> <module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Assiging" /> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/coder" />
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/Assiging/feature_hashing.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/coder/digits_recognizer.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="true" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" /> <option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" /> <option name="REDIRECT_INPUT" value="false" />
@ -131,6 +129,9 @@
<module name="wozek" /> <module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/coder" /> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/coder" />
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
@ -215,17 +216,17 @@
<list> <list>
<item itemvalue="Python.image" /> <item itemvalue="Python.image" />
<item itemvalue="Python.main" /> <item itemvalue="Python.main" />
<item itemvalue="Python.feature_hashing" />
<item itemvalue="Python.train_nn" /> <item itemvalue="Python.train_nn" />
<item itemvalue="Python.rocognizer" /> <item itemvalue="Python.rocognizer" />
<item itemvalue="Python.digits_recognizer" />
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.digits_recognizer" />
<item itemvalue="Python.image" /> <item itemvalue="Python.image" />
<item itemvalue="Python.rocognizer" /> <item itemvalue="Python.rocognizer" />
<item itemvalue="Python.train_nn" /> <item itemvalue="Python.train_nn" />
<item itemvalue="Python.main" /> <item itemvalue="Python.main" />
<item itemvalue="Python.feature_hashing" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -257,6 +258,11 @@
<workItem from="1590230578314" duration="1895000" /> <workItem from="1590230578314" duration="1895000" />
<workItem from="1590235510565" duration="925000" /> <workItem from="1590235510565" duration="925000" />
<workItem from="1590340739871" duration="8052000" /> <workItem from="1590340739871" duration="8052000" />
<workItem from="1590359007619" duration="127000" />
<workItem from="1590409526059" duration="4922000" />
<workItem from="1590423569728" duration="2532000" />
<workItem from="1590436739719" duration="6325000" />
<workItem from="1590443664804" duration="2683000" />
</task> </task>
<task id="LOCAL-00001" summary="create Shelf"> <task id="LOCAL-00001" summary="create Shelf">
<created>1589815443652</created> <created>1589815443652</created>
@ -328,7 +334,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1589972251988</updated> <updated>1589972251988</updated>
</task> </task>
<option name="localTasksCounter" value="11" /> <task id="LOCAL-00011" summary="new dataset">
<created>1590359074952</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1590359074952</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -358,7 +371,8 @@
<MESSAGE value="zwiekszenie dokladnosci" /> <MESSAGE value="zwiekszenie dokladnosci" />
<MESSAGE value="finding barcode" /> <MESSAGE value="finding barcode" />
<MESSAGE value="po" /> <MESSAGE value="po" />
<option name="LAST_COMMIT_MESSAGE" value="po" /> <MESSAGE value="new dataset" />
<option name="LAST_COMMIT_MESSAGE" value="new dataset" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="115" y="162" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1589923610328"> <state x="115" y="162" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1589923610328">
@ -381,14 +395,14 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="208" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1589845242796" /> <state width="1493" height="208" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1589845242796" />
<state x="277" y="57" key="SettingsEditor" timestamp="1589845139218"> <state x="277" y="57" key="SettingsEditor" timestamp="1590443566792">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="277" y="57" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1589845139218" /> <state x="277" y="57" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1590443566792" />
<state x="361" y="145" key="Vcs.Push.Dialog.v2" timestamp="1589972275899"> <state x="361" y="145" key="Vcs.Push.Dialog.v2" timestamp="1590359093497">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="361" y="145" key="Vcs.Push.Dialog.v2/0.0.1536.824@0.0.1536.824" timestamp="1589972275899" /> <state x="361" y="145" key="Vcs.Push.Dialog.v2/0.0.1536.824@0.0.1536.824" timestamp="1590359093496" />
<state x="54" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1589918982407"> <state x="54" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1589918982407">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.8 (AL-2020)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="PyDocumentationSettings"> <component name="PyDocumentationSettings">

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,39 @@
import numpy as np
import torch
import torchvision
import matplotlib.pyplot as plt
from time import time
from torchvision import datasets, transforms
from torch import nn, optim
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,)),
])
trainset = datasets.MNIST('PATH_TO_STORE_TRAINSET', download=True, train=True, transform=transform)
valset = datasets.MNIST('PATH_TO_STORE_TESTSET', download=True, train=False, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)
valloader = torch.utils.data.DataLoader(valset, batch_size=64, shuffle=True)
dataiter = iter(trainloader)
images, labels = dataiter.next()
print(images.shape)
print(labels.shape)
plt.imshow(images[0].numpy().squeeze(), cmap='gray_r')
plt.show()
# building nn model
input_size = 784
hidden_sizes = [128, 64]
output_size = 10
model = nn.Sequential(nn.Linear(input_size, hidden_sizes[0]),
nn.ReLU(),
nn.Linear(hidden_sizes[0], hidden_sizes[1]),
nn.ReLU(),
nn.Linear(hidden_sizes[1], output_size),
nn.LogSoftmax(dim=1))
print(model)

View File

@ -11,7 +11,8 @@ import cv2
train_data = np.genfromtxt('dataset/train.csv', delimiter=',', skip_header=1, max_rows=20000, encoding='utf-8') train_data = np.genfromtxt('dataset/train.csv', delimiter=',', skip_header=1, max_rows=20000, encoding='utf-8')
test_data = np.genfromtxt('dataset/test.csv', delimiter=',', skip_header=1, max_rows=20000, encoding='utf-8') test_data = np.genfromtxt('dataset/test.csv', delimiter=',', skip_header=1, max_rows=20000, encoding='utf-8')
# train_data = pd.read_csv('dataset/train.csv')
# test_data = pd.read_csv('dataset/test.csv')
# training # training
# recznie napisane cyfry # recznie napisane cyfry
@ -20,33 +21,35 @@ digits = datasets.load_digits()
y = digits.target y = digits.target
x = digits.images.reshape((len(digits.images), -1)) x = digits.images.reshape((len(digits.images), -1))
# print(type(y[0]), type(x[0]))
# ogarnac zbior, zwiekszyc warstwy # ogarnac zbior, zwiekszyc warstwy
x_train = train_data[0:20000, 1:] # x_train = train_data.iloc[:, 1:].values.astype('float32')
y_train = train_data[0:20000, 0] # y_train = train_data.iloc[:, 0].values.astype('int32')
x_test = test_data[0:20000] # x_test = test_data.values.astype('float32')
y_test = test_data[0:20000, 0]
x_train = train_data[0:10000, 1:]
y_train = train_data[0:10000, 0]
x_test = train_data[10001:20000, 1:]
y_test = train_data[10001:20000, 0].astype('int')
print(type(y_test[0]), type(x_test[0]))
# x_train = x[:900] # x_train = x[:900]
# y_train = y[:900] # y_train = y[:900]
# x_test = x[900:] # x_test = x[900:]
# y_test = y[900:] # y_test = y[900:]
print(x_test[0].shape, y_test[9].shape) # 500, 500, 500, 500, 500
mlp = MLPClassifier(hidden_layer_sizes=(150, 100, 100, 100), activation='logistic', alpha=1e-4,
mlp = MLPClassifier(hidden_layer_sizes=(100, 100, 100, 100), activation='logistic', alpha=1e-4,
solver='sgd', tol=0.000000000001, random_state=1, solver='sgd', tol=0.000000000001, random_state=1,
learning_rate_init=.1, verbose=True, max_iter=1000) learning_rate_init=.1, verbose=True, max_iter=10000)
mlp.fit(x_train, y_train) mlp.fit(x_train, y_train)
print(123456789)
predictions = mlp.predict(x_test) predictions = mlp.predict(x_test)
print(123456789)
print("Accuracy: ", accuracy_score(y_test, predictions)) print("Accuracy: ", accuracy_score(y_test, predictions))
# image # image
img = cv2.cvtColor(cv2.imread('test5.jpg'), cv2.COLOR_BGR2GRAY) img = cv2.cvtColor(cv2.imread('test5.jpg'), cv2.COLOR_BGR2GRAY)
@ -54,11 +57,10 @@ img = cv2.blur(img, (9, 9)) # poprawia jakosc
img = cv2.resize(img, (28, 28), interpolation=cv2.INTER_AREA) img = cv2.resize(img, (28, 28), interpolation=cv2.INTER_AREA)
img = img.reshape((len(img), -1)) img = img.reshape((len(img), -1))
print(type(img)) # print(type(img))
print(img.shape) # print(img.shape)
print(img) # plt.imshow(img ,cmap='binary')
plt.imshow(img ,cmap='binary') # plt.show()
plt.show()
data = [] data = []
@ -69,13 +71,14 @@ for i in range(rows):
if k > 225: if k > 225:
k = 0 # brak czarnego k = 0 # brak czarnego
else: else:
k = 1 k = 255
data.append(k) data.append(k)
data = np.asarray(data, dtype=np.float32) data = np.asarray(data, dtype=np.float64)
print(data) # print(data)
print(type(data))
predictions = mlp.predict([data]) predictions = mlp.predict([data])
print("Liczba to:", predictions[0]) print("Liczba to:", predictions[0].astype('int'))