Converts a datum to an array. Note that the label is not returned, as one can easily get it by calling datum.label.
(datum)
| 82 | |
| 83 | |
| 84 | def datum_to_array(datum): |
| 85 | """Converts a datum to an array. Note that the label is not returned, |
| 86 | as one can easily get it by calling datum.label. |
| 87 | """ |
| 88 | if len(datum.data): |
| 89 | return np.fromstring(datum.data, dtype=np.uint8).reshape( |
| 90 | datum.channels, datum.height, datum.width) |
| 91 | else: |
| 92 | return np.array(datum.float_data).astype(float).reshape( |
| 93 | datum.channels, datum.height, datum.width) |
| 94 | |
| 95 | |
| 96 | ## Pre-processing |