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

質問編集履歴

2

プログラム追加

2022/02/09 21:51

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -26,4 +26,62 @@
26
26
  File "<stdin>", line 1, in <module>
27
27
  NameError: name 'ks' is not defined
28
28
  >>> exit ()
29
+ ```
30
+
31
+ プログラム
32
+ ```Python 3.7
33
+ from keras.models import Sequential
34
+ from keras.layers import Dense, Activation
35
+ from keras.utils import np_utils
36
+
37
+ #ダミーデータ
38
+ data = np.random.random((1000, 784))
39
+ labels = np.random.randit(10, size=(1000, 1))
40
+ labels = np_utils.to_categorical(labels, 10)
41
+
42
+ model = seuentil()
43
+ model.add(Dense(64, activtion='relu', input_dim=784))
44
+ model.add(Dense(64, ctivation='relu'))
45
+ model.add(Dense(10, ctivation='softmax'))
46
+
47
+ #モデルのコンパイル
48
+ model.compile(optimizer='rmsprop',
49
+ loss='categorical_crossentropy',
50
+ metrics=['accracy'])
51
+
52
+ #学習を行う
53
+ model.fit(data, labels)
54
+ ```
55
+ ```エラー
56
+ ---------------------------------------------------------------------------
57
+ ImportError Traceback (most recent call last)
58
+ <ipython-input-1-95d31656bd9c> in <module>()
59
+ ----> 1 from keras.models import Sequential
60
+ 2 from keras.layers import Dense, Activation
61
+ 3 from keras.utils import np_utils
62
+ 4
63
+ 5 #ダミーデータ
64
+
65
+ ~/.local/lib/python3.7/site-packages/keras/__init__.py in <module>()
66
+ 23
67
+ 24 # See b/110718070#comment18 for more details about this import.
68
+ ---> 25 from keras import models
69
+ 26
70
+ 27 from keras.engine.input_layer import Input
71
+
72
+ ~/.local/lib/python3.7/site-packages/keras/models.py in <module>()
73
+ 17
74
+ 18 import tensorflow.compat.v2 as tf
75
+ ---> 19 from keras import backend
76
+ 20 from keras import metrics as metrics_module
77
+ 21 from keras import optimizer_v1
78
+
79
+ ~/.local/lib/python3.7/site-packages/keras/backend.py in <module>()
80
+ 35 from tensorflow.python.distribute import distribute_coordinator as dc
81
+ 36 from tensorflow.python.distribute import distribute_coordinator_context as dc_context
82
+ ---> 37 from tensorflow.python.eager.context import get_config
83
+ 38 from tensorflow.python.framework import config
84
+ 39 from keras import backend_config
85
+
86
+ ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (/Users/****/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/tensorflow_core/python/eager/context.py)
29
87
  ```

1

リンクを追加しました

2021/06/02 02:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  以前こちらで([リンク内容](https://teratail.com/questions/341442#reply-469809))TensorFlowのインストールが分からずに質問したのですが, その時にバージョンが大切だと知り、
2
- TensorFlowの1.15には、Kerasは2.2.4まで動くと保証されているので、2.2.4をインストールしても、importができていない様です。
2
+ TensorFlowの1.15には、Kerasは2.2.4まで動くと保証されているので([リンク内容](https://qiita.com/somethingwonderful/items/e94f6d5a57052b8076c9))、2.2.4をインストールしても、importができていない様です。
3
3
  これは、何が原因なのでしょうか?
4
4
  また、どうしたら解決できますか?
5
5