Skip to content

Commit e819ebb

Browse files
committed
new tethers
1 parent 4f41351 commit e819ebb

File tree

2 files changed

+293
-0
lines changed

2 files changed

+293
-0
lines changed

.tether/man/keras.utils.Config.txt

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
Help on class Config in module keras.src.utils.config:
2+
3+
class Config(builtins.object)
4+
| Config(**kwargs)
5+
|
6+
| A Config is a dict-like container for named values.
7+
|
8+
| It offers a few advantages over a plain dict:
9+
|
10+
| - Setting and retrieving values via attribute setting / getting.
11+
| - Ability to freeze the config to ensure no accidental config modifications
12+
| occur past a certain point in your program.
13+
| - Easy serialization of the whole config as JSON.
14+
|
15+
| Examples:
16+
|
17+
| ```python
18+
| # Create a config via constructor arguments
19+
| config = Config("learning_rate"=0.1, "momentum"=0.9)
20+
|
21+
| # Then keep adding to it via attribute-style setting
22+
| config.use_ema = True
23+
| config.ema_overwrite_frequency = 100
24+
|
25+
| # You can also add attributes via dict-like access
26+
| config["seed"] = 123
27+
|
28+
| # You can retrieve entries both via attribute-style
29+
| # access and dict-style access
30+
| assert config.seed == 100
31+
| assert config["learning_rate"] == 0.1
32+
| ```
33+
|
34+
| A config behaves like a dict:
35+
|
36+
| ```python
37+
| config = Config("learning_rate"=0.1, "momentum"=0.9)
38+
| for k, v in config.items():
39+
| print(f"{k}={v}")
40+
|
41+
| print(f"keys: {list(config.keys())}")
42+
| print(f"values: {list(config.values())}")
43+
| ```
44+
|
45+
| In fact, it can be turned into one:
46+
|
47+
| ```python
48+
| config = Config("learning_rate"=0.1, "momentum"=0.9)
49+
| dict_config = config.as_dict()
50+
| ```
51+
|
52+
| You can easily serialize a config to JSON:
53+
|
54+
| ```python
55+
| config = Config("learning_rate"=0.1, "momentum"=0.9)
56+
|
57+
| json_str = config.to_json()
58+
| ```
59+
|
60+
| You can also freeze a config to prevent further changes:
61+
|
62+
| ```python
63+
| config = Config()
64+
| config.optimizer = "adam"
65+
| config.seed = 123
66+
|
67+
| # Freeze the config to prevent changes.
68+
| config.freeze()
69+
| assert config.frozen
70+
|
71+
| config.foo = "bar" # This will raise an error.
72+
| ```
73+
|
74+
| Methods defined here:
75+
|
76+
| __contains__(self, item)
77+
|
78+
| __delitem__(self, key)
79+
|
80+
| __getattr__(self, name)
81+
|
82+
| __getitem__(self, key)
83+
|
84+
| __init__(self, **kwargs)
85+
| Initialize self. See help(type(self)) for accurate signature.
86+
|
87+
| __iter__(self)
88+
|
89+
| __len__(self)
90+
|
91+
| __repr__(self)
92+
| Return repr(self).
93+
|
94+
| __setattr__(
95+
| self,
96+
| name,
97+
| value
98+
| )
99+
| Implement setattr(self, name, value).
100+
|
101+
| __setitem__(
102+
| self,
103+
| key,
104+
| item
105+
| )
106+
|
107+
| as_dict(self)
108+
|
109+
| freeze(self)
110+
| Marks the config as frozen, preventing any ulterior modification.
111+
|
112+
| get(
113+
| self,
114+
| keyname,
115+
| value=None
116+
| )
117+
|
118+
| items(self)
119+
|
120+
| keys(self)
121+
|
122+
| pop(self, *args)
123+
|
124+
| to_json(self)
125+
|
126+
| unfreeze(self)
127+
|
128+
| update(
129+
| self,
130+
| *args,
131+
| **kwargs
132+
| )
133+
|
134+
| values(self)
135+
|
136+
| ----------------------------------------------------------------------
137+
| Readonly properties defined here:
138+
|
139+
| frozen
140+
| Returns True if the config is frozen.
141+
|
142+
| ----------------------------------------------------------------------
143+
| Data descriptors defined here:
144+
|
145+
| __dict__
146+
| dictionary for instance variables
147+
|
148+
| __weakref__
149+
| list of weak references to the object
150+
|
151+
| ----------------------------------------------------------------------
152+
| Data and other attributes defined here:
153+
|
154+
| __attrs__ = None
155+
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
Help on class KerasFileEditor in module keras.src.saving.file_editor:
2+
3+
class KerasFileEditor(builtins.object)
4+
| KerasFileEditor(filepath)
5+
|
6+
| Utility to inspect, edit, and resave Keras weights files.
7+
|
8+
| You will find this class useful when adapting
9+
| an old saved weights file after having made
10+
| architecture changes to a model.
11+
|
12+
| Args:
13+
| filepath: The path to a local file to inspect and edit.
14+
|
15+
| Examples:
16+
|
17+
| ```python
18+
| editor = KerasFileEditor("my_model.weights.h5")
19+
|
20+
| # Displays current contents
21+
| editor.summary()
22+
|
23+
| # Remove the weights of an existing layer
24+
| editor.delete_object("layers/dense_2")
25+
|
26+
| # Add the weights of a new layer
27+
| editor.add_object("layers/einsum_dense", weights={"0": ..., "1": ...})
28+
|
29+
| # Save the weights of the edited model
30+
| editor.resave_weights("edited_model.weights.h5")
31+
| ```
32+
|
33+
| Methods defined here:
34+
|
35+
| __init__(self, filepath)
36+
| Initialize self. See help(type(self)) for accurate signature.
37+
|
38+
| add_object(
39+
| self,
40+
| object_path,
41+
| weights
42+
| )
43+
| Add a new object to the file (e.g. a layer).
44+
|
45+
| Args:
46+
| object_path: String, full path of the
47+
| object to add (e.g. `"layers/dense_2"`).
48+
| weights: Dict mapping weight names to weight
49+
| values (arrays),
50+
| e.g. `{"0": kernel_value, "1": bias_value}`.
51+
|
52+
| add_weights(
53+
| self,
54+
| object_name,
55+
| weights
56+
| )
57+
| Add one or more new weights to an existing object.
58+
|
59+
| Args:
60+
| object_name: String, name or path of the
61+
| object to add the weights to
62+
| (e.g. `"dense_2"` or `"layers/dense_2"`).
63+
| weights: Dict mapping weight names to weight
64+
| values (arrays),
65+
| e.g. `{"0": kernel_value, "1": bias_value}`.
66+
|
67+
| compare(self, reference_model)
68+
| Compares the opened file to a reference model.
69+
|
70+
| This method will list all mismatches between the
71+
| currently opened file and the provided reference model.
72+
|
73+
| Args:
74+
| reference_model: Model instance to compare to.
75+
|
76+
| Returns:
77+
| Dict with the following keys:
78+
| `'status'`, `'error_count'`, `'match_count'`.
79+
| Status can be `'success'` or `'error'`.
80+
| `'error_count'` is the number of mismatches found.
81+
| `'match_count'` is the number of matching weights found.
82+
|
83+
| delete_object(self, object_name)
84+
| Removes an object from the file (e.g. a layer).
85+
|
86+
| Args:
87+
| object_name: String, name or path of the
88+
| object to delete (e.g. `"dense_2"` or
89+
| `"layers/dense_2"`).
90+
|
91+
| delete_weight(
92+
| self,
93+
| object_name,
94+
| weight_name
95+
| )
96+
| Removes a weight from an existing object.
97+
|
98+
| Args:
99+
| object_name: String, name or path of the
100+
| object from which to remove the weight
101+
| (e.g. `"dense_2"` or `"layers/dense_2"`).
102+
| weight_name: String, name of the weight to
103+
| delete (e.g. `"0"`).
104+
|
105+
| rename_object(
106+
| self,
107+
| object_name,
108+
| new_name
109+
| )
110+
| Rename an object in the file (e.g. a layer).
111+
|
112+
| Args:
113+
| object_name: String, name or path of the
114+
| object to rename (e.g. `"dense_2"` or
115+
| `"layers/dense_2"`).
116+
| new_name: String, new name of the object.
117+
|
118+
| resave_weights(self, filepath)
119+
|
120+
| save(self, filepath)
121+
| Save the edited weights file.
122+
|
123+
| Args:
124+
| filepath: Path to save the file to.
125+
| Must be a `.weights.h5` file.
126+
|
127+
| summary(self)
128+
| Prints the weight structure of the opened file.
129+
|
130+
| ----------------------------------------------------------------------
131+
| Data descriptors defined here:
132+
|
133+
| __dict__
134+
| dictionary for instance variables
135+
|
136+
| __weakref__
137+
| list of weak references to the object
138+

0 commit comments

Comments
 (0)