Fill a queue with input data
(T, shape, num_labels, fixed_shape)
| 21 | |
| 22 | |
| 23 | def generate_data(T, shape, num_labels, fixed_shape): |
| 24 | ''' |
| 25 | Fill a queue with input data |
| 26 | ''' |
| 27 | log.info("Generating T={} sequence batches".format(T)) |
| 28 | |
| 29 | generate_input_init_net = core.Net('generate_input_init') |
| 30 | queue = generate_input_init_net.CreateBlobsQueue( |
| 31 | [], "inputqueue", num_blobs=1, capacity=T, |
| 32 | ) |
| 33 | label_queue = generate_input_init_net.CreateBlobsQueue( |
| 34 | [], "labelqueue", num_blobs=1, capacity=T, |
| 35 | ) |
| 36 | |
| 37 | workspace.RunNetOnce(generate_input_init_net) |
| 38 | generate_input_net = core.Net('generate_input') |
| 39 | |
| 40 | generate_input_net.EnqueueBlobs([queue, "scratch"], ["scratch"]) |
| 41 | generate_input_net.EnqueueBlobs([label_queue, "label_scr"], ["label_scr"]) |
| 42 | np.random.seed(2603) |
| 43 | |
| 44 | entry_counts = [] |
| 45 | for t in range(T): |
| 46 | if (t % (max(10, T // 10)) == 0): |
| 47 | print("Generating data {}/{}".format(t, T)) |
| 48 | # Randomize the seqlength |
| 49 | random_shape = ( |
| 50 | [np.random.randint(1, shape[0])] + shape[1:] |
| 51 | if t > 0 and not fixed_shape else shape |
| 52 | ) |
| 53 | X = np.random.rand(*random_shape).astype(np.float32) |
| 54 | batch_size = random_shape[1] |
| 55 | L = num_labels * batch_size |
| 56 | labels = (np.random.rand(random_shape[0]) * L).astype(np.int32) |
| 57 | workspace.FeedBlob("scratch", X) |
| 58 | workspace.FeedBlob("label_scr", labels) |
| 59 | workspace.RunNetOnce(generate_input_net.Proto()) |
| 60 | entry_counts.append(random_shape[0] * random_shape[1]) |
| 61 | |
| 62 | log.info("Finished data generation") |
| 63 | |
| 64 | return queue, label_queue, entry_counts |
| 65 | |
| 66 | |
| 67 | def create_model(args, queue, label_queue, input_shape): |
no test coverage detected
searching dependent graphs…