teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

17

2019/06/13 08:03

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -19,6 +19,8 @@
19
19
  ```
20
20
  コード
21
21
  ```
22
+ module.py
23
+ ————————————
22
24
  from tkinter import *
23
25
  from PIL improt Image ,ImageGrab
24
26
  import tkinter.filedialog as fd
@@ -88,6 +90,12 @@
88
90
  y2= y1 + self.__canvas.winfo_height()
89
91
  self.__canvas.create_rectangle(x1,y1,x2,y2,fill=‘white’,width=0)
90
92
  self.__label.config(text=‘判定結果: ?’)
93
+ ————————————
94
+ start_up.py
95
+ ————————————
96
+ from module import Drawing
97
+ draw = Drawing()
98
+ draw.run()
91
99
  ```
92
100
  ### 試したこと
93
101
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意

16

2019/06/13 08:03

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -63,18 +63,31 @@
63
63
  #数字判定予測
64
64
  def __predict_digits(self,target_data):
65
65
  digits = ds.load_digits()
66
- learn_data = digits.data
66
+ learn_data = digits.data #学習データ
67
- result_data = digits.data
67
+ result_data = digits.target #結果データ
68
68
  model =SVC(gamma = 0.001)
69
69
  model.fit(learn_data,result_data)
70
70
  n = model.predict([target_data])
71
71
  self.__label.config(text = ‘判定結果: ‘ +str(n[0]))
72
72
  print(n)
73
73
  #判定
74
+ def __judge_digits(self):
75
+ x1 = self.__window.winfo_riootx() + self.__canvas.winfo_x()
76
+ y1 = self.__window.winfo_riooty() + self.__canvas.winfo_y()
77
+ x2 = x1 + self.__canvas.winfo_width()
78
+ y2 = y1 + self.__canvas.winfo_height()
79
+ img = ImageGrap.grap()
80
+ img = img.crop((x1,y1,x2,y2))
81
+ target_data = self.__convert_image(img)
74
- def __predict_digits(self,target_data):
82
+ self.__predict_digits(target_data)
83
+ #消去
84
+ def __clear(self):
85
+ x1= 0
86
+ y1= 0
75
- digits = ds.load_digits()
87
+ x2= x1 + self.__canvas.winfo_width()
76
- learn_data = digits.data #学習データ
88
+ y2= y1 + self.__canvas.winfo_height()
89
+ self.__canvas.create_rectangle(x1,y1,x2,y2,fill=‘white’,width=0)
77
- result_data = digits.target #結果データ
90
+ self.__label.config(text=‘判定結果: ?’)
78
91
  ```
79
92
  ### 試したこと
80
93
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意

15

2019/06/13 08:00

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -57,7 +57,24 @@
57
57
  gray_image = img.convert(‘L’)
58
58
  gray_imgae = gray_image.resize((8,8),Image.ANTIALIAS)
59
59
  img_array = numpy.asarray(gray_image,dtype = float)
60
- img_array = numpy.floor(16-16*(
60
+ img_array = numpy.floor(16-16*(img_array/256))
61
+ img_array = img_array.flatten()
62
+ return img_array
63
+ #数字判定予測
64
+ def __predict_digits(self,target_data):
65
+ digits = ds.load_digits()
66
+ learn_data = digits.data
67
+ result_data = digits.data
68
+ model =SVC(gamma = 0.001)
69
+ model.fit(learn_data,result_data)
70
+ n = model.predict([target_data])
71
+ self.__label.config(text = ‘判定結果: ‘ +str(n[0]))
72
+ print(n)
73
+ #判定
74
+ def __predict_digits(self,target_data):
75
+ digits = ds.load_digits()
76
+ learn_data = digits.data #学習データ
77
+ result_data = digits.target #結果データ
61
78
  ```
62
79
  ### 試したこと
63
80
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意

14

2019/06/13 07:44

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
File without changes

13

2019/06/13 07:34

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -25,10 +25,10 @@
25
25
  import sklearn.svm import SVC
26
26
  import numpy
27
27
  class Drawing:
28
- 画面描画
28
+ #コンストラクタ
29
29
  def __init__(self):
30
30
  self.__window = self.__create_window()
31
- #
31
+ #画面を構成
32
32
  def __create_window(self):
33
33
  window = Tk()
34
34
  window.geometry(‘400x400’)
@@ -44,9 +44,20 @@
44
44
  clear_button = Button(text =‘消去’, command = self.__clear)
45
45
  return window
46
46
 
47
- #
47
+ #実行
48
48
  def run(self):
49
+ self.__window.mainloop()
50
+ #マウスを押す
51
+ def __on_pressed(self,e):
49
- self.
52
+ x = e.x
53
+ y = e.y
54
+ self.__canvas.create_oval(x-15,y-15,x+15,y+15,fill=‘black’
55
+ #画像データを数値リストに変換
56
+ def __convert_image(self,img):
57
+ gray_image = img.convert(‘L’)
58
+ gray_imgae = gray_image.resize((8,8),Image.ANTIALIAS)
59
+ img_array = numpy.asarray(gray_image,dtype = float)
60
+ img_array = numpy.floor(16-16*(
50
61
  ```
51
62
  ### 試したこと
52
63
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意

12

2019/06/13 04:11

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
 
17
17
  ### 該当のソースコード
18
+ g
18
19
  ```
19
20
  コード
20
21
  ```

11

2019/06/13 02:59

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -16,6 +16,8 @@
16
16
 
17
17
  ### 該当のソースコード
18
18
  ```
19
+ コード
20
+ ```
19
21
  from tkinter import *
20
22
  from PIL improt Image ,ImageGrab
21
23
  import tkinter.filedialog as fd
@@ -51,7 +53,4 @@
51
53
 
52
54
  ### 補足情報(FW/ツールのバージョンなど)
53
55
 
54
- ここにより詳細な情報を記載してください。
56
+ ここにより詳細な情報を記載してください。
55
- ```ああああ
56
- コード
57
- ```

10

2019/06/13 02:57

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -51,4 +51,7 @@
51
51
 
52
52
  ### 補足情報(FW/ツールのバージョンなど)
53
53
 
54
- ここにより詳細な情報を記載してください。
54
+ ここにより詳細な情報を記載してください。
55
+ ```ああああ
56
+ コード
57
+ ```

9

2019/06/13 02:57

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
 
17
17
  ### 該当のソースコード
18
+ ```
18
19
  from tkinter import *
19
20
  from PIL improt Image ,ImageGrab
20
21
  import tkinter.filedialog as fd
@@ -43,6 +44,7 @@
43
44
  #
44
45
  def run(self):
45
46
  self.
47
+ ```
46
48
  ### 試したこと
47
49
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意
48
50
  ・画像を8×8ピクセルにリサイズ

8

2019/06/13 02:56

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -15,8 +15,7 @@
15
15
 
16
16
 
17
17
  ### 該当のソースコード
18
- ソースコード
19
- ```from tkinter import *
18
+ from tkinter import *
20
19
  from PIL improt Image ,ImageGrab
21
20
  import tkinter.filedialog as fd
22
21
  import sklearn.svm import SVC

7

2019/06/13 02:53

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -15,9 +15,8 @@
15
15
 
16
16
 
17
17
  ### 該当のソースコード
18
- ```
19
18
  ソースコード
20
- from tkinter import *
19
+ ```from tkinter import *
21
20
  from PIL improt Image ,ImageGrab
22
21
  import tkinter.filedialog as fd
23
22
  import sklearn.svm import SVC

6

2019/06/13 02:53

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -23,7 +23,7 @@
23
23
  import sklearn.svm import SVC
24
24
  import numpy
25
25
  class Drawing:
26
- #画面描画
26
+ 画面描画
27
27
  def __init__(self):
28
28
  self.__window = self.__create_window()
29
29
  #

5

2019/06/13 00:05

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -15,11 +15,36 @@
15
15
 
16
16
 
17
17
  ### 該当のソースコード
18
-
19
18
  ```
20
19
  ソースコード
20
+ from tkinter import *
21
+ from PIL improt Image ,ImageGrab
22
+ import tkinter.filedialog as fd
23
+ import sklearn.svm import SVC
24
+ import numpy
25
+ class Drawing:
21
- ```
26
+ #画面描画
27
+ def __init__(self):
28
+ self.__window = self.__create_window()
29
+ #
30
+ def __create_window(self):
31
+ window = Tk()
32
+ window.geometry(‘400x400’)
33
+ window.tilte(‘数字判断アプリ’)
34
+ self.__label = Label(text = ‘判断結果:?’)
35
+ self.__label = Label.pack()
36
+ self.__canvas = Canvas(width = 200, bg = ‘white’)
37
+ self.__canvas.bind(‘<ButtonPress-1>’,self__.on_pressed)
38
+ self.__canvas.bind(‘<B1-Motion>’,self.__on_dragged
39
+ self.__canvas.pack()
40
+ judge_button= Button(text =‘判定’, command = self.__judge_digit)
41
+ judge_button.pack()
42
+ clear_button = Button(text =‘消去’, command = self.__clear)
43
+ return window
22
44
 
45
+ #
46
+ def run(self):
47
+ self.
23
48
  ### 試したこと
24
49
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意
25
50
  ・画像を8×8ピクセルにリサイズ

4

2019/06/13 00:00

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  ### 試したこと
24
24
  ・学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意
25
+ ・画像を8×8ピクセルにリサイズ
25
26
 
26
27
  ### 補足情報(FW/ツールのバージョンなど)
27
28
 

3

2019/06/12 10:49

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,9 @@
1
1
  ### 前提・実現したいこと
2
2
  前提として
3
- ・インターネットからデータは取れない。
3
+ ・インターネットから既存の手書きデータは取れない。
4
4
  ・手書きのみ
5
5
  ・キャンバスに描画した数字を画像⇨文字列に変換して学習モデルと比較
6
- ・scikit-learn で学習モデルを作成
6
+ ・scikit-learn で教師あり学習モデルを作成
7
7
 
8
8
  現在キャンバス上に描画した数字を判定して予測結果を出力するプログラムを作成してしています。
9
9
  この予測結果の正解率が40%ほどで90%にあげたいと考えています。

2

2019/06/12 10:09

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,7 @@
3
3
  ・インターネットからデータは取れない。
4
4
  ・手書きのみ
5
5
  ・キャンバスに描画した数字を画像⇨文字列に変換して学習モデルと比較
6
+ ・scikit-learn で学習モデルを作成
6
7
 
7
8
  現在キャンバス上に描画した数字を判定して予測結果を出力するプログラムを作成してしています。
8
9
  この予測結果の正解率が40%ほどで90%にあげたいと考えています。
@@ -20,7 +21,7 @@
20
21
  ```
21
22
 
22
23
  ### 試したこと
23
- 学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意
24
+ 学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意
24
25
 
25
26
  ### 補足情報(FW/ツールのバージョンなど)
26
27
 

1

2019/06/12 10:05

投稿

okusann
okusann

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,22 +1,26 @@
1
1
  ### 前提・実現したいこと
2
+ 前提として
3
+ ・インターネットからデータは取れない。
4
+ ・手書きのみ
5
+ ・キャンバスに描画した数字を画像⇨文字列に変換して学習モデルと比較
6
+
2
7
  現在キャンバス上に描画した数字を判定して予測結果を出力するプログラムを作成してしています。
3
8
  この予測結果の正解率が40%ほどで90%にあげたいと考えています。
4
9
 
5
10
 
11
+
6
12
  ### 発生している問題・エラーメッセージ
7
- が40%ほどで低状態す。
13
+ ```をあげるには、学習するための画像を増やせばしょうか
8
- ```
9
- エラーメッセージ
10
- ```
11
14
 
15
+
12
16
  ### 該当のソースコード
13
17
 
14
- ```Python3.6
18
+ ```
15
19
  ソースコード
16
20
  ```
17
21
 
18
22
  ### 試したこと
19
- 手書き数字(0〜9)を各70枚ほど用意
23
+ 学習モデルに使用する手書き数字画像(0〜9)を各70枚ほど用意
20
24
 
21
25
  ### 補足情報(FW/ツールのバージョンなど)
22
26