Given a Record containing blob_references and arrays, which is either a list of numpy arrays or a Record containing numpy arrays, feeds the record to the current workspace.
(blob_record, arrays, ws=None)
| 1161 | |
| 1162 | |
| 1163 | def FeedRecord(blob_record, arrays, ws=None): |
| 1164 | """ |
| 1165 | Given a Record containing blob_references and arrays, which is either |
| 1166 | a list of numpy arrays or a Record containing numpy arrays, feeds the |
| 1167 | record to the current workspace. |
| 1168 | """ |
| 1169 | |
| 1170 | def feed(b, v): |
| 1171 | if ws is None: |
| 1172 | workspace.FeedBlob(str(b), v) |
| 1173 | else: |
| 1174 | ws.create_blob(str(b)) |
| 1175 | ws.blobs[str(b)].feed(v) |
| 1176 | assert isinstance(blob_record, Field) |
| 1177 | field_blobs = blob_record.field_blobs() |
| 1178 | assert all(isinstance(v, BlobReference) for v in field_blobs) |
| 1179 | if isinstance(arrays, Field): |
| 1180 | # TODO: check schema |
| 1181 | arrays = arrays.field_blobs() |
| 1182 | assert len(arrays) == len(field_blobs), ( |
| 1183 | 'Values must contain exactly %d ndarrays.' % len(field_blobs) |
| 1184 | ) |
| 1185 | for blob, array in zip(field_blobs, arrays): |
| 1186 | feed(blob, array) |
| 1187 | |
| 1188 | |
| 1189 | def NewRecord(net, schema): |
searching dependent graphs…