You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Therefore, it is possible to override the `make` method to implement the three-part make pattern by using the `yield` statement to return the fetched data and computed result as above.
173
+
174
+
#### Use Cases
175
+
176
+
This pattern is particularly valuable for:
177
+
178
+
-**Machine learning model training**: Hours-long training sessions
The exact same effect may be achieved by overriding the `make` method as a generator function using the `yield` statement to return the fetched data and computed result as above:
222
+
223
+
```python
224
+
@schema
225
+
classImageAnalysis(dj.Computed):
226
+
definition ="""
227
+
# Complex image analysis results
228
+
-> Image
229
+
---
230
+
analysis_result : longblob
231
+
processing_time : float
232
+
"""
233
+
234
+
defmake(self, key):
235
+
fetched_data = (Image & key).fetch1('image'),
236
+
computed_result =yield fetched_data
237
+
238
+
if computed_result isNone:
239
+
# Expensive computation that could take hours
240
+
import time
241
+
start_time = time.time()
242
+
result = complex_image_analysis(image_data)
243
+
processing_time = time.time() - start_time
244
+
computed_result = result, processing_time
245
+
yield computed_result
246
+
247
+
result, processing_time = computed_result
248
+
self.insert1(dict(key,
249
+
analysis_result=result,
250
+
processing_time=processing_time))
251
+
yield# yield control back to the caller
252
+
```
253
+
We expect that most users will prefer to use the three-part implementation over the generator function implementation due to its conceptual complexity.
254
+
68
255
## Populate
69
256
70
257
The inherited `populate` method of `dj.Imported` and `dj.Computed` automatically calls
0 commit comments