manisdeep 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mani Tehrani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: manisdeep
3
+ Version: 2.0.0
4
+ Summary: A modular deep-learning framework with configurable neural networks and multimodal training APIs
5
+ Author: Mani Tehrani
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy>=1.24
11
+ Provides-Extra: neural
12
+ Requires-Dist: torch>=2.1; extra == "neural"
13
+ Provides-Extra: tensorflow
14
+ Requires-Dist: tensorflow>=2.15; extra == "tensorflow"
15
+ Requires-Dist: pandas>=2.0; extra == "tensorflow"
16
+ Requires-Dist: scikit-learn>=1.3; extra == "tensorflow"
17
+ Provides-Extra: pytorch
18
+ Requires-Dist: torch>=2.1; extra == "pytorch"
19
+ Requires-Dist: torchvision>=0.16; extra == "pytorch"
20
+ Requires-Dist: pandas>=2.0; extra == "pytorch"
21
+ Requires-Dist: scikit-learn>=1.3; extra == "pytorch"
22
+ Provides-Extra: tabular
23
+ Requires-Dist: pandas>=2.0; extra == "tabular"
24
+ Requires-Dist: scikit-learn>=1.3; extra == "tabular"
25
+ Provides-Extra: text
26
+ Requires-Dist: torch>=2.1; extra == "text"
27
+ Requires-Dist: pandas>=2.0; extra == "text"
28
+ Requires-Dist: scikit-learn>=1.3; extra == "text"
29
+ Provides-Extra: audio
30
+ Requires-Dist: torch>=2.1; extra == "audio"
31
+ Requires-Dist: librosa>=0.10; extra == "audio"
32
+ Requires-Dist: scikit-learn>=1.3; extra == "audio"
33
+ Provides-Extra: video
34
+ Requires-Dist: torch>=2.1; extra == "video"
35
+ Requires-Dist: opencv-python>=4.8; extra == "video"
36
+ Requires-Dist: scikit-learn>=1.3; extra == "video"
37
+ Provides-Extra: detection
38
+ Requires-Dist: torch>=2.1; extra == "detection"
39
+ Requires-Dist: torchvision>=0.16; extra == "detection"
40
+ Requires-Dist: Pillow>=10; extra == "detection"
41
+ Provides-Extra: all
42
+ Requires-Dist: torch>=2.1; extra == "all"
43
+ Requires-Dist: torchvision>=0.16; extra == "all"
44
+ Requires-Dist: tensorflow>=2.15; extra == "all"
45
+ Requires-Dist: pandas>=2.0; extra == "all"
46
+ Requires-Dist: scikit-learn>=1.3; extra == "all"
47
+ Requires-Dist: librosa>=0.10; extra == "all"
48
+ Requires-Dist: opencv-python>=4.8; extra == "all"
49
+ Requires-Dist: Pillow>=10; extra == "all"
50
+ Requires-Dist: joblib>=1.3; extra == "all"
51
+ Dynamic: license-file
52
+ Dynamic: requires-python
53
+
54
+ # Mani's Deep 2.0.0
55
+
56
+ Mani's Deep 2.0 preserves the 1.0 `deep()` training API and adds a configurable neural-network engine for general supervised learning.
57
+
58
+ ## Install
59
+
60
+ ```bash
61
+ pip install "manisdeep[neural]"
62
+ ```
63
+
64
+ For the original multimodal APIs, install the relevant extras, for example `pip install "manisdeep[pytorch,audio,video,detection]"`.
65
+
66
+ ## New neural-network engine
67
+
68
+ ```python
69
+ from manisdeep import NeuralNetwork
70
+
71
+ # Learn y = x1 + x2 from examples; the relationship is learned from data.
72
+ X = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6],
73
+ [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]
74
+ y = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
75
+
76
+ model = NeuralNetwork(
77
+ task="regression",
78
+ hidden_layers=(128, 64, 32),
79
+ activation="gelu",
80
+ dropout=0.05,
81
+ batch_norm=True,
82
+ optimizer="adamw",
83
+ learning_rate=0.001,
84
+ )
85
+ model.fit(X, y, epochs=500, batch_size=4, patience=60)
86
+ print(model.predict([[20, 21]]))
87
+ print(model.evaluate(X, y))
88
+ model.save("models/addition_network.pt")
89
+
90
+ # Reload in another script:
91
+ from manisdeep import load_neural_model
92
+ loaded = load_neural_model("models/addition_network.pt")
93
+ print(loaded.predict([[20, 21]]))
94
+ ```
95
+
96
+ The model is not given an addition formula. It fits the relationship represented by the training examples. Neural networks approximate patterns and are not guaranteed to extrapolate correctly outside the training distribution; provide broad, representative data and evaluate on held-out examples.
97
+
98
+ ## Multi-output regression
99
+
100
+ ```python
101
+ model = NeuralNetwork(task="regression", hidden_layers=(256, 128, 64))
102
+ model.fit(X, y_two_outputs, epochs=300)
103
+ result = model.predict([[2.0, 5.0]])
104
+ ```
105
+
106
+ For `y_two_outputs`, provide an array shaped `(number_of_samples, 2)`.
107
+
108
+ ## Classification
109
+
110
+ ```python
111
+ model = NeuralNetwork(task="classification", hidden_layers=(128, 64))
112
+ model.fit(features, labels, epochs=150)
113
+ print(model.predict(new_features))
114
+ print(model.predict_proba(new_features))
115
+ ```
116
+
117
+ Classification labels may be strings or integers. `predict_proba` returns class probabilities in `model.classes_` order.
118
+
119
+ ## Existing 1.0 API remains
120
+
121
+ ```python
122
+ from manisdeep import deep
123
+
124
+ deep(
125
+ dataset="dataset/",
126
+ data_type="image",
127
+ framework="pytorch",
128
+ task="classification",
129
+ epochs=10,
130
+ batch_size=16,
131
+ save_path="models/image_run",
132
+ )
133
+ ```
134
+
135
+ The older image, tabular, text, audio, video and COCO object-detection training routes are retained. Their 1.0 limitations still apply; 2.0's new neural engine does not automatically turn those baseline classifiers into generative models, speech recognition, or advanced video understanding.
136
+
137
+ ## NeuralNetwork options
138
+
139
+ - `task`: `regression` or `classification`
140
+ - `hidden_layers`: hidden layer widths, e.g. `(256, 128, 64)`
141
+ - `activation`: `relu`, `gelu`, `silu`, `tanh`, `leaky_relu`, `elu`
142
+ - `dropout`: float in `[0, 1)`
143
+ - `batch_norm`: enable/disable batch normalization
144
+ - `optimizer`: `adam`, `adamw`, `sgd`
145
+ - `learning_rate`, `weight_decay`, `device`, `random_state`, `gradient_clip`
146
+
147
+ `fit` supports `epochs`, `batch_size`, `validation_split`, `patience`, `min_delta`, `lr_scheduler`, and `verbose`. Training uses validation loss for early stopping and restores the best validation checkpoint.
@@ -0,0 +1,94 @@
1
+ # Mani's Deep 2.0.0
2
+
3
+ Mani's Deep 2.0 preserves the 1.0 `deep()` training API and adds a configurable neural-network engine for general supervised learning.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install "manisdeep[neural]"
9
+ ```
10
+
11
+ For the original multimodal APIs, install the relevant extras, for example `pip install "manisdeep[pytorch,audio,video,detection]"`.
12
+
13
+ ## New neural-network engine
14
+
15
+ ```python
16
+ from manisdeep import NeuralNetwork
17
+
18
+ # Learn y = x1 + x2 from examples; the relationship is learned from data.
19
+ X = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6],
20
+ [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]
21
+ y = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
22
+
23
+ model = NeuralNetwork(
24
+ task="regression",
25
+ hidden_layers=(128, 64, 32),
26
+ activation="gelu",
27
+ dropout=0.05,
28
+ batch_norm=True,
29
+ optimizer="adamw",
30
+ learning_rate=0.001,
31
+ )
32
+ model.fit(X, y, epochs=500, batch_size=4, patience=60)
33
+ print(model.predict([[20, 21]]))
34
+ print(model.evaluate(X, y))
35
+ model.save("models/addition_network.pt")
36
+
37
+ # Reload in another script:
38
+ from manisdeep import load_neural_model
39
+ loaded = load_neural_model("models/addition_network.pt")
40
+ print(loaded.predict([[20, 21]]))
41
+ ```
42
+
43
+ The model is not given an addition formula. It fits the relationship represented by the training examples. Neural networks approximate patterns and are not guaranteed to extrapolate correctly outside the training distribution; provide broad, representative data and evaluate on held-out examples.
44
+
45
+ ## Multi-output regression
46
+
47
+ ```python
48
+ model = NeuralNetwork(task="regression", hidden_layers=(256, 128, 64))
49
+ model.fit(X, y_two_outputs, epochs=300)
50
+ result = model.predict([[2.0, 5.0]])
51
+ ```
52
+
53
+ For `y_two_outputs`, provide an array shaped `(number_of_samples, 2)`.
54
+
55
+ ## Classification
56
+
57
+ ```python
58
+ model = NeuralNetwork(task="classification", hidden_layers=(128, 64))
59
+ model.fit(features, labels, epochs=150)
60
+ print(model.predict(new_features))
61
+ print(model.predict_proba(new_features))
62
+ ```
63
+
64
+ Classification labels may be strings or integers. `predict_proba` returns class probabilities in `model.classes_` order.
65
+
66
+ ## Existing 1.0 API remains
67
+
68
+ ```python
69
+ from manisdeep import deep
70
+
71
+ deep(
72
+ dataset="dataset/",
73
+ data_type="image",
74
+ framework="pytorch",
75
+ task="classification",
76
+ epochs=10,
77
+ batch_size=16,
78
+ save_path="models/image_run",
79
+ )
80
+ ```
81
+
82
+ The older image, tabular, text, audio, video and COCO object-detection training routes are retained. Their 1.0 limitations still apply; 2.0's new neural engine does not automatically turn those baseline classifiers into generative models, speech recognition, or advanced video understanding.
83
+
84
+ ## NeuralNetwork options
85
+
86
+ - `task`: `regression` or `classification`
87
+ - `hidden_layers`: hidden layer widths, e.g. `(256, 128, 64)`
88
+ - `activation`: `relu`, `gelu`, `silu`, `tanh`, `leaky_relu`, `elu`
89
+ - `dropout`: float in `[0, 1)`
90
+ - `batch_norm`: enable/disable batch normalization
91
+ - `optimizer`: `adam`, `adamw`, `sgd`
92
+ - `learning_rate`, `weight_decay`, `device`, `random_state`, `gradient_clip`
93
+
94
+ `fit` supports `epochs`, `batch_size`, `validation_split`, `patience`, `min_delta`, `lr_scheduler`, and `verbose`. Training uses validation loss for early stopping and restores the best validation checkpoint.
@@ -0,0 +1,5 @@
1
+ from .core import deep
2
+ from .neural import NeuralNetwork, load_neural_model
3
+ from .version import __version__
4
+
5
+ __all__ = ["deep", "NeuralNetwork", "load_neural_model", "__version__"]
@@ -0,0 +1,133 @@
1
+ from pathlib import Path
2
+ import json
3
+ import warnings
4
+
5
+
6
+ def deep(
7
+ dataset,
8
+ data_type,
9
+ framework="pytorch",
10
+ task="classification",
11
+ epochs=10,
12
+ batch_size=16,
13
+ save_path="manisdeep_model",
14
+ *,
15
+ target_col=None,
16
+ text_col=None,
17
+ image_size=(128, 128),
18
+ validation_split=0.2,
19
+ learning_rate=0.001,
20
+ sample_rate=16000,
21
+ audio_duration=3.0,
22
+ video_frames=8,
23
+ num_classes=None,
24
+ annotations=None,
25
+ random_state=42,
26
+ ):
27
+ """
28
+ One-call training API for Mani's Deep 1.0.0.
29
+
30
+ Implemented:
31
+ image + classification: TensorFlow or PyTorch
32
+ tabular + classification: TensorFlow or PyTorch
33
+ text + classification: PyTorch
34
+ audio + classification: PyTorch
35
+ video + classification: PyTorch
36
+ image + object_detection: PyTorch (COCO JSON annotations)
37
+
38
+ Classification folder convention:
39
+ dataset/class_name/file.ext
40
+
41
+ Text CSV:
42
+ target_col is required; text_col is required unless the CSV has
43
+ exactly one non-target column.
44
+
45
+ Object detection:
46
+ dataset is an image directory; annotations is a COCO-format JSON file.
47
+ """
48
+ dataset = Path(dataset).expanduser()
49
+ save_path = Path(save_path).expanduser()
50
+ data_type = str(data_type).lower().strip()
51
+ framework = str(framework).lower().strip()
52
+ task = str(task).lower().strip()
53
+
54
+ if not dataset.exists():
55
+ raise FileNotFoundError(f"Dataset not found: {dataset}")
56
+ if epochs < 1 or batch_size < 1:
57
+ raise ValueError("epochs and batch_size must be positive integers.")
58
+ if not 0 < validation_split < 1:
59
+ raise ValueError("validation_split must be between 0 and 1.")
60
+ if framework not in {"tensorflow", "pytorch"}:
61
+ raise ValueError("framework must be 'tensorflow' or 'pytorch'.")
62
+
63
+ save_path.mkdir(parents=True, exist_ok=True)
64
+
65
+ if task == "object_detection":
66
+ if data_type != "image":
67
+ raise ValueError("object_detection requires data_type='image'.")
68
+ if framework != "pytorch":
69
+ raise NotImplementedError(
70
+ "Mani's Deep 1.0 object detection currently uses the PyTorch engine."
71
+ )
72
+ if annotations is None:
73
+ raise ValueError("Pass annotations='path/to/instances.json' in COCO format.")
74
+ result = _train_detection(
75
+ dataset, Path(annotations), epochs, batch_size, save_path, learning_rate
76
+ )
77
+ elif task == "classification":
78
+ if data_type in {"image", "tabular"}:
79
+ if framework == "tensorflow":
80
+ from .tf_engine import train_tf
81
+ result = train_tf(
82
+ dataset, data_type, epochs, batch_size, save_path,
83
+ target_col, image_size, validation_split, learning_rate, random_state
84
+ )
85
+ else:
86
+ from .torch_classic import train_torch_classic
87
+ result = train_torch_classic(
88
+ dataset, data_type, epochs, batch_size, save_path,
89
+ target_col, image_size, validation_split, learning_rate, random_state
90
+ )
91
+ elif data_type in {"text", "audio", "video"}:
92
+ if framework != "pytorch":
93
+ raise NotImplementedError(
94
+ f"{data_type} classification currently uses framework='pytorch'."
95
+ )
96
+ from .torch_media import train_media
97
+ result = train_media(
98
+ dataset, data_type, epochs, batch_size, save_path,
99
+ target_col, text_col, validation_split, learning_rate,
100
+ sample_rate, audio_duration, video_frames, random_state
101
+ )
102
+ else:
103
+ raise ValueError(
104
+ "data_type must be image, tabular, text, audio or video."
105
+ )
106
+ else:
107
+ raise NotImplementedError(
108
+ "Supported tasks: 'classification' and 'object_detection'."
109
+ )
110
+
111
+ metadata = {
112
+ "manisdeep_version": "2.0.0",
113
+ "data_type": data_type,
114
+ "framework": framework,
115
+ "task": task,
116
+ "epochs": epochs,
117
+ "batch_size": batch_size,
118
+ "result": result,
119
+ }
120
+ (save_path / "manisdeep_metadata.json").write_text(
121
+ json.dumps(metadata, indent=2, ensure_ascii=False, default=str),
122
+ encoding="utf-8",
123
+ )
124
+ print(f"\\nMani's Deep: completed. Output saved to: {save_path}")
125
+ return result
126
+
127
+
128
+ def _train_detection(image_dir, annotation_file, epochs, batch_size,
129
+ save_path, learning_rate):
130
+ from .torch_detection import train_detection
131
+ return train_detection(
132
+ image_dir, annotation_file, epochs, batch_size, save_path, learning_rate
133
+ )