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

質問編集履歴

2

タイトルが正しくなかった

2018/09/07 10:37

投稿

Shirui
Shirui

スコア7

title CHANGED
@@ -1,1 +1,1 @@
1
- Pythonの"self"は,他インスタンスの属性(attribute)を取得できますか?self.attr(attr)はどの様な意味ですか?
1
+ Pythonのself.attr(attr)はどの様な意味ですか?(引数の後ろ()の中に,引数がある)
body CHANGED
File without changes

1

間違って理解していたところを補充

2018/09/07 10:37

投稿

Shirui
Shirui

スコア7

title CHANGED
File without changes
body CHANGED
@@ -38,10 +38,71 @@
38
38
  ```
39
39
  0.
40
40
  **lr = float(K.get_value(self.model.optimizer.lr))**コードでは,
41
- selfを用い,「他クラスのインスタンスの属性を得ている」様に見えますが,この様な理解で宜しいですか?
41
+ ~~selfを用い,「他クラスのインスタンスの属性を得ている」様に見えますが,この様な理解で宜しいですか?~~
42
+ スーパークラスのinit()にself.model = Noneコードがありました.
43
+ 結論として,『selfを用い,「他クラスのインスタンスの属性を得ている」』ではないです.
44
+ 以下スーパークラスのCallback(object)となります.
42
45
 
43
46
  0.
44
47
  **lr = self.schedule(epoch, lr)**コードでは,
45
48
  selfを用い,得た属性の後ろに又属性を加えているのですが(関数の使用に似ているのですが),この様な使い方の意味は,どの様なものでしょうか?
46
49
 
47
- 宜しくお願い致します.
50
+ 宜しくお願い致します.
51
+ ```Python
52
+ class Callback(object):
53
+ """Abstract base class used to build new callbacks.
54
+
55
+ # Properties
56
+ params: dict. Training parameters
57
+ (eg. verbosity, batch size, number of epochs...).
58
+ model: instance of `keras.models.Model`.
59
+ Reference of the model being trained.
60
+
61
+ The `logs` dictionary that callback methods
62
+ take as argument will contain keys for quantities relevant to
63
+ the current batch or epoch.
64
+
65
+ Currently, the `.fit()` method of the `Sequential` model class
66
+ will include the following quantities in the `logs` that
67
+ it passes to its callbacks:
68
+
69
+ on_epoch_end: logs include `acc` and `loss`, and
70
+ optionally include `val_loss`
71
+ (if validation is enabled in `fit`), and `val_acc`
72
+ (if validation and accuracy monitoring are enabled).
73
+ on_batch_begin: logs include `size`,
74
+ the number of samples in the current batch.
75
+ on_batch_end: logs include `loss`, and optionally `acc`
76
+ (if accuracy monitoring is enabled).
77
+ """
78
+
79
+ def __init__(self):
80
+ self.validation_data = None
81
+ self.model = None
82
+
83
+ def set_params(self, params):
84
+ self.params = params
85
+
86
+ def set_model(self, model):
87
+ self.model = model
88
+
89
+ def on_epoch_begin(self, epoch, logs=None):
90
+ pass
91
+
92
+ def on_epoch_end(self, epoch, logs=None):
93
+ pass
94
+
95
+ def on_batch_begin(self, batch, logs=None):
96
+ pass
97
+
98
+ def on_batch_end(self, batch, logs=None):
99
+ pass
100
+
101
+ def on_train_begin(self, logs=None):
102
+ pass
103
+
104
+ def on_train_end(self, logs=None):
105
+ pass
106
+
107
+
108
+ ```