MCPcopy Index your code
hub / github.com/pytorch/pytorch / generate_data

Function generate_data

caffe2/python/lstm_benchmark.py:23–64  ·  view source on GitHub ↗

Fill a queue with input data

(T, shape, num_labels, fixed_shape)

Source from the content-addressed store, hash-verified

21
22
23def 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
67def create_model(args, queue, label_queue, input_shape):

Callers 1

Caffe2LSTMFunction · 0.70

Calls 11

ProtoMethod · 0.95
infoMethod · 0.80
NetMethod · 0.80
randintMethod · 0.80
astypeMethod · 0.80
rangeFunction · 0.50
maxFunction · 0.50
formatMethod · 0.45
seedMethod · 0.45
randMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…