質問編集履歴

10

2020/02/22 16:53

投稿

masa.taka
masa.taka

スコア22

test CHANGED
File without changes
test CHANGED
@@ -98,8 +98,6 @@
98
98
 
99
99
 
100
100
 
101
- モデルの詳細(その他ファイル含め)を、gitにアップしました。
101
+ gitにアップしました。
102
102
 
103
103
  (全体)https://github.com/masanori-takada/image_recog
104
-
105
- (モデル)cifar10-cnn.ipynb

9

2020/02/22 16:52

投稿

masa.taka
masa.taka

スコア22

test CHANGED
File without changes
test CHANGED
@@ -98,256 +98,8 @@
98
98
 
99
99
 
100
100
 
101
- ### pyファイル
101
+ モデルの詳細(その他ファイル含め)を、gitにアップしました。
102
102
 
103
+ (全体)https://github.com/masanori-takada/image_recog
103
104
 
104
-
105
- ```ここに言語名を入力
106
-
107
- import pickle
108
-
109
- import numpy as np
110
-
111
- from flask import Flask, render_template, request, redirect, url_for
112
-
113
-
114
-
115
- from keras.models import load_model
116
-
117
- import cv2
118
-
119
- import numpy as np
120
-
121
- import matplotlib.pyplot as plt
122
-
123
- import io
124
-
125
- import tensorflow as tf
126
-
127
- import sys
128
-
129
-
130
-
131
- app = Flask(__name__)
105
+ (モデル)cifar10-cnn.ipynb
132
-
133
-
134
-
135
- # 機械学習モデルの読込
136
-
137
- model = load_model("./data/cnn_model.h5")
138
-
139
- model.load_weights("./data/cnn_weights.h5")
140
-
141
-
142
-
143
- graph = tf.get_default_graph()
144
-
145
-
146
-
147
-
148
-
149
- @app.route("/")
150
-
151
- def index():
152
-
153
- return render_template("index.html")
154
-
155
-
156
-
157
-
158
-
159
- @app.route("/result", methods=['POST'])
160
-
161
- def result():
162
-
163
- if request.files["image"]:
164
-
165
- img_file = request.files["image"]
166
-
167
- f = img_file.stream.read()
168
-
169
- bin_data = io.BytesIO(f)
170
-
171
- file_bytes = np.asarray(bytearray(bin_data.read()), dtype=np.uint8)
172
-
173
-
174
-
175
- img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
176
-
177
- img = cv2.resize(img, (32, 32))
178
-
179
-
180
-
181
- in_rows = 32
182
-
183
- in_cols = 32
184
-
185
- in_colors = 3
186
-
187
-
188
-
189
- labels = [
190
-
191
- 'airplane',
192
-
193
- 'automobile',
194
-
195
- 'bird',
196
-
197
- 'cat',
198
-
199
- 'deer',
200
-
201
- 'dog',
202
-
203
- 'frog',
204
-
205
- 'horse',
206
-
207
- 'ship',
208
-
209
- 'truck'
210
-
211
- ]
212
-
213
-
214
-
215
- img = img.reshape(-1, in_rows, in_cols,
216
-
217
- in_colors).astype("float32") / 255
218
-
219
-
220
-
221
- with graph.as_default():
222
-
223
- r = model.predict(img, batch_size=32, verbose=1)
224
-
225
- res = r[0]
226
-
227
- print(res, file=sys.stdout)
228
-
229
- return render_template("result.html", res=res, labels=labels)
230
-
231
- else:
232
-
233
- return redirect(url_for('index'))
234
-
235
-
236
-
237
-
238
-
239
- if __name__ == '__main__':
240
-
241
- app.run(debug=True)
242
-
243
- ```
244
-
245
- ### index.html
246
-
247
-
248
-
249
- ```ここに言語名を入力
250
-
251
- <!DOCTYPE html>
252
-
253
- <html>
254
-
255
-
256
-
257
- <head>
258
-
259
- <title>アプリ</title>
260
-
261
- <link rel="stylesheet" type="text/css" href="../static/css/style.css">
262
-
263
- </head>
264
-
265
-
266
-
267
- <body class="main">
268
-
269
-
270
-
271
- <div class="heading">
272
-
273
- <h1>画像認識アプリ Image-Recognition</h1>
274
-
275
- </div>
276
-
277
-
278
-
279
-
280
-
281
- <div>
282
-
283
- <form method="post" action="/result" enctype="multipart/form-data">
284
-
285
- <p>
286
-
287
- <input type="file" name="image" accept="image/png, image/jpeg" placeholder="Image Url">
288
-
289
- </p>
290
-
291
- <p>
292
-
293
- <input type="submit" value="Go!">
294
-
295
- </p>
296
-
297
- </form>
298
-
299
- </div>
300
-
301
-
302
-
303
- </body>
304
-
305
-
306
-
307
- </html>
308
-
309
- ```
310
-
311
-
312
-
313
- ### result.html
314
-
315
-
316
-
317
- ```ここに言語名を入力
318
-
319
- <!DOCTYPE html>
320
-
321
- <html>
322
-
323
-
324
-
325
- <head>
326
-
327
- <title>Result</title>le.css
328
-
329
- <link rel="stylesheet" type="text/css" href="../static/css/style.css">
330
-
331
- </head>
332
-
333
-
334
-
335
- <body class="main">
336
-
337
-
338
-
339
- <div class="heading">
340
-
341
- 予測結果は...<h1 align="center">{{labels[res.argmax()]}}</h1>
342
-
343
- </div>
344
-
345
-
346
-
347
- </body>
348
-
349
-
350
-
351
- </html>
352
-
353
- ```

8

2020/02/22 16:50

投稿

masa.taka
masa.taka

スコア22

test CHANGED
@@ -1 +1 @@
1
- (助けて下さい)tensorflowのエラー。
1
+ tensorflowのエラー。
test CHANGED
File without changes

7

修正

2020/02/22 16:47

投稿

masa.taka
masa.taka

スコア22

test CHANGED
File without changes
test CHANGED
@@ -30,17 +30,69 @@
30
30
 
31
31
  ```
32
32
 
33
+ Traceback (most recent call last):
34
+
35
+ File "/Users/takadasusumuten/opt/anaconda3/bin/flask", line 10, in <module>
36
+
37
+ sys.exit(main())
38
+
39
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 966, in main
40
+
41
+ cli.main(prog_name="python -m flask" if as_module else None)
42
+
43
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 586, in main
44
+
33
- tensorflow.python.framework.errors_impl.FailedPreconditionError:
45
+ return super(FlaskGroup, self).main(*args, **kwargs)
34
-
46
+
35
- Error while reading resource variable conv2d_10/kernel from Container: localhost.
47
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/click/core.py", line 717, in main
36
-
37
- This could mean that the variable was uninitialized.
48
+
38
-
39
- Not found: Container localhost does not exist.
49
+ rv = self.invoke(ctx)
50
+
40
-
51
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
52
+
41
- (Could not find resource: localhost/conv2d_10/kernel)
53
+ return _process_result(sub_ctx.command.invoke(sub_ctx))
54
+
42
-
55
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/click/core.py", line 956, in invoke
56
+
57
+ return ctx.invoke(self.callback, **ctx.params)
58
+
59
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke
60
+
61
+ return callback(*args, **kwargs)
62
+
63
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
64
+
65
+ return ctx.invoke(f, obj, *args, **kwargs)
66
+
67
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke
68
+
69
+ return callback(*args, **kwargs)
70
+
71
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 848, in run_command
72
+
73
+ app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
74
+
75
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 305, in __init__
76
+
77
+ self._load_unlocked()
78
+
79
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 330, in _load_unlocked
80
+
81
+ self._app = rv = self.loader()
82
+
83
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 388, in load_app
84
+
85
+ app = locate_app(self, import_name, name)
86
+
87
+ File "/Users/takadasusumuten/opt/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
88
+
89
+ __import__(module_name)
90
+
91
+ File "/Users/takadasusumuten/Desktop/python/img_recog/img_recog.py", line 19, in <module>
92
+
93
+ graph = tf.get_default_graph()
94
+
43
- [[{{node conv2d_10/convolution/ReadVariableOp}}]]
95
+ AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
44
96
 
45
97
  ```
46
98
 

6

2020/02/18 14:38

投稿

masa.taka
masa.taka

スコア22

test CHANGED
File without changes
test CHANGED
File without changes

5

2020/02/18 13:58

投稿

masa.taka
masa.taka

スコア22

test CHANGED
@@ -1 +1 @@
1
- (助けて下さい)tensorflowのエラー
1
+ (助けて下さい)tensorflowのエラー
test CHANGED
File without changes

4

2020/02/18 13:58

投稿

masa.taka
masa.taka

スコア22

test CHANGED
@@ -1 +1 @@
1
- tensorflowのFailedPreconditionError
1
+ (助けて下さい)tensorflowのエラー
test CHANGED
File without changes

3

修正

2020/02/18 13:57

投稿

masa.taka
masa.taka

スコア22

test CHANGED
@@ -1 +1 @@
1
- tensorflowのエラー
1
+ tensorflowのFailedPreconditionError
test CHANGED
File without changes

2

2020/02/17 00:50

投稿

masa.taka
masa.taka

スコア22

test CHANGED
@@ -1 +1 @@
1
- flaskとOpenCVのエラー
1
+ tensorflowのエラー
test CHANGED
File without changes

1

2020/02/16 11:21

投稿

masa.taka
masa.taka

スコア22

test CHANGED
@@ -1 +1 @@
1
- flaskとOpenCVによる画像認識のエラー
1
+ flaskとOpenCVのエラー
test CHANGED
File without changes