File size: 21,603 Bytes
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b04778
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b04778
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
9b04778
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
 
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
 
 
3bd77c9
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
 
 
 
 
 
 
 
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
 
 
 
 
3bd77c9
 
3e3cb7a
 
3bd77c9
 
 
 
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e3cb7a
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
9b04778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3bd77c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "gradient": {
          "editing": false,
          "id": "ac5a4cf0-d9d2-47b5-9633-b53f8d99a4d2",
          "kernelId": ""
        },
        "id": "SiTIpPjArIyr"
      },
      "source": [
        "# Los Angeles MIDI Dataset Metadata Maker (ver. 3.0)\n",
        "\n",
        "***\n",
        "\n",
        "Powered by tegridy-tools: https://github.com/asigalov61/tegridy-tools\n",
        "\n",
        "***\n",
        "\n",
        "#### Project Los Angeles\n",
        "\n",
        "#### Tegridy Code 2023\n",
        "\n",
        "***"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "gradient": {
          "editing": false,
          "id": "fa0a611c-1803-42ae-bdf6-a49b5a4e781b",
          "kernelId": ""
        },
        "id": "gOd93yV0sGd2"
      },
      "source": [
        "# (SETUP ENVIRONMENT)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "gradient": {
          "editing": false,
          "id": "a1a45a91-d909-4fd4-b67a-5e16b971d179",
          "kernelId": ""
        },
        "id": "fX12Yquyuihc"
      },
      "outputs": [],
      "source": [
        "#@title Install all dependencies (run only once per session)\n",
        "\n",
        "!git clone https://github.com/asigalov61/tegridy-tools\n",
        "!pip install tqdm"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "gradient": {
          "editing": false,
          "id": "b8207b76-9514-4c07-95db-95a4742e52c5",
          "kernelId": ""
        },
        "id": "z7n9vnKmug1J"
      },
      "outputs": [],
      "source": [
        "#@title Import all needed modules\n",
        "\n",
        "print('Loading needed modules. Please wait...')\n",
        "import os\n",
        "\n",
        "import math\n",
        "import statistics\n",
        "import random\n",
        "from collections import Counter\n",
        "import pickle\n",
        "\n",
        "from tqdm import tqdm\n",
        "\n",
        "if not os.path.exists('/content/Dataset'):\n",
        "    os.makedirs('/content/Dataset')\n",
        "\n",
        "print('Loading TMIDIX module...')\n",
        "os.chdir('/content/tegridy-tools/tegridy-tools')\n",
        "\n",
        "import TMIDIX\n",
        "\n",
        "print('Done!')\n",
        "\n",
        "os.chdir('/content/')\n",
        "print('Enjoy! :)')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "gradient": {
          "editing": false,
          "id": "20b8698a-0b4e-4fdb-ae49-24d063782e77",
          "kernelId": ""
        },
        "id": "ObPxlEutsQBj"
      },
      "source": [
        "# (DOWNLOAD SOURCE MIDI DATASET)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Download original LAKH MIDI Dataset\n",
        "\n",
        "%cd /content/Dataset/\n",
        "\n",
        "!wget 'http://hog.ee.columbia.edu/craffel/lmd/lmd_full.tar.gz'\n",
        "!tar -xvf 'lmd_full.tar.gz'\n",
        "!rm 'lmd_full.tar.gz'\n",
        "\n",
        "%cd /content/"
      ],
      "metadata": {
        "cellView": "form",
        "id": "7aItlhq9cRxZ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "S69mWHAcn5Bg"
      },
      "outputs": [],
      "source": [
        "#@title Mount Google Drive\n",
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JwrqQeie08t0"
      },
      "source": [
        "# (FILE LIST)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "DuVWtdDNcqKh"
      },
      "outputs": [],
      "source": [
        "#@title Save file list\n",
        "###########\n",
        "\n",
        "print('Loading MIDI files...')\n",
        "print('This may take a while on a large dataset in particular.')\n",
        "\n",
        "dataset_addr = \"/content/Dataset\"\n",
        "# os.chdir(dataset_addr)\n",
        "filez = list()\n",
        "for (dirpath, dirnames, filenames) in os.walk(dataset_addr):\n",
        "    filez += [os.path.join(dirpath, file) for file in filenames]\n",
        "print('=' * 70)\n",
        "\n",
        "if filez == []:\n",
        "    print('Could not find any MIDI files. Please check Dataset dir...')\n",
        "    print('=' * 70)\n",
        "\n",
        "print('Randomizing file list...')\n",
        "random.shuffle(filez)\n",
        "\n",
        "TMIDIX.Tegridy_Any_Pickle_File_Writer(filez, '/content/filez')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "qI_adhjojrJ9"
      },
      "outputs": [],
      "source": [
        "#@title Load file list\n",
        "filez = TMIDIX.Tegridy_Any_Pickle_File_Reader('/content/filez')\n",
        "print('Done!')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FLxHvO-wlwfU"
      },
      "source": [
        "# (PROCESS)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "CeGo7CruaCJQ",
        "cellView": "form"
      },
      "outputs": [],
      "source": [
        "#@title Process MIDIs with TMIDIX MIDI processor\n",
        "\n",
        "print('=' * 70)\n",
        "print('TMIDIX MIDI Processor')\n",
        "print('=' * 70)\n",
        "print('Starting up...')\n",
        "print('=' * 70)\n",
        "\n",
        "###########\n",
        "\n",
        "START_FILE_NUMBER = 0\n",
        "LAST_SAVED_BATCH_COUNT = 0\n",
        "\n",
        "input_files_count = START_FILE_NUMBER\n",
        "files_count = LAST_SAVED_BATCH_COUNT\n",
        "\n",
        "melody_chords_f = []\n",
        "\n",
        "stats = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
        "\n",
        "print('Processing MIDI files. Please wait...')\n",
        "print('=' * 70)\n",
        "\n",
        "for f in tqdm(filez[START_FILE_NUMBER:]):\n",
        "    try:\n",
        "        input_files_count += 1\n",
        "\n",
        "        fn = os.path.basename(f)\n",
        "        fn1 = fn.split('.mid')[0]\n",
        "\n",
        "        #=======================================================\n",
        "        # START PROCESSING\n",
        "        \n",
        "        opus = TMIDIX.midi2opus(open(f, 'rb').read())\n",
        "        \n",
        "        opus_events_matrix = []\n",
        "        \n",
        "        itrack0 = 1\n",
        "       \n",
        "        while itrack0 < len(opus):\n",
        "            for event in opus[itrack0]:         \n",
        "                    opus_events_matrix.append(event)\n",
        "            itrack0 += 1\n",
        "        \n",
        "        #=======================================================\n",
        "        \n",
        "        ms_score = TMIDIX.opus2score(TMIDIX.to_millisecs(opus))\n",
        "\n",
        "        ms_events_matrix = []\n",
        "        \n",
        "        itrack1 = 1\n",
        "       \n",
        "        while itrack1 < len(ms_score):\n",
        "            for event in ms_score[itrack1]:         \n",
        "                if event[0] == 'note':\n",
        "                    ms_events_matrix.append(event)\n",
        "            itrack1 += 1\n",
        "\n",
        "        ms_events_matrix.sort(key=lambda x: x[1])\n",
        "        \n",
        "        #=======================================================\n",
        "\n",
        "        # Convering MIDI to score with MIDI.py module\n",
        "        score = TMIDIX.opus2score(opus)\n",
        "\n",
        "        # INSTRUMENTS CONVERSION CYCLE\n",
        "\n",
        "        events_matrix = []\n",
        "        full_events_matrix = []\n",
        "        \n",
        "        itrack = 1\n",
        "        patches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
        "\n",
        "        while itrack < len(score):\n",
        "            for event in score[itrack]:         \n",
        "                if event[0] == 'note' or event[0] == 'patch_change':\n",
        "                    events_matrix.append(event)\n",
        "                full_events_matrix.append(event)\n",
        "            itrack += 1\n",
        "            \n",
        "        full_events_matrix.sort(key=lambda x: x[1])\n",
        "        events_matrix.sort(key=lambda x: x[1])\n",
        "        \n",
        "        events_matrix1 = []\n",
        "\n",
        "        for event in events_matrix:\n",
        "            if event[0] == 'patch_change':\n",
        "                patches[event[2]] = event[3]\n",
        "\n",
        "            if event[0] == 'note':\n",
        "                event.extend([patches[event[3]]])\n",
        "                events_matrix1.append(event)\n",
        "\n",
        "        if len(events_matrix1) > 32:           \n",
        "            \n",
        "            events_matrix1.sort(key=lambda x: x[1])\n",
        "\n",
        "            for e in events_matrix1:\n",
        "                if e[0] == 'note':\n",
        "                    if e[3] == 9:\n",
        "                        e[4] = ((abs(e[4]) % 128) + 128)\n",
        "                    else:\n",
        "                        e[4] = (abs(e[4]) % 128)\n",
        "\n",
        "            pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]\n",
        "            pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
        "            \n",
        "            patches = sorted([y[6] for y in events_matrix1])\n",
        "            patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]\n",
        "            patches_counts.sort(key = lambda x: x[0])\n",
        "            \n",
        "            midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
        "            if len(midi_patches) == 0:\n",
        "                midi_patches = [0]\n",
        "                \n",
        "            times = []\n",
        "            pt = ms_events_matrix[0][1]\n",
        "            start = True\n",
        "            for e in ms_events_matrix:\n",
        "                if (e[1]-pt) != 0 or start == True:\n",
        "                    times.append((e[1]-pt))\n",
        "                    start = False\n",
        "                pt = e[1]\n",
        "                \n",
        "            times_sum = min(10000000, sum(times))\n",
        "            \n",
        "            durs = [e[2] for e in ms_events_matrix]\n",
        "            vels = [e[5] for e in ms_events_matrix]\n",
        "            \n",
        "            avg_time = int(sum(times) / len(times))\n",
        "            avg_dur = int(sum(durs) / len(durs))\n",
        "            avg_vel = int(sum(vels) / len(vels))\n",
        "            \n",
        "            mode_time = statistics.mode(times)\n",
        "            mode_dur = statistics.mode(durs)\n",
        "            mode_vel = statistics.mode(vels)\n",
        "            \n",
        "            median_time = int(statistics.median(times))\n",
        "            median_dur = int(statistics.median(durs))\n",
        "            median_vel = int(statistics.median(vels))\n",
        "            \n",
        "            text_events_list = ['text_event', \n",
        "                          'text_event_08', \n",
        "                          'text_event_09', \n",
        "                          'text_event_0a', \n",
        "                          'text_event_0b', \n",
        "                          'text_event_0c',\n",
        "                          'text_event_0d',\n",
        "                          'text_event_0e',\n",
        "                          'text_event_0f']\n",
        "            \n",
        "            text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])\n",
        "            lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])\n",
        "            \n",
        "            chords = []\n",
        "            pe = ms_events_matrix[0]\n",
        "            cho = []\n",
        "            for e in ms_events_matrix:\n",
        "                if (e[1] - pe[1]) == 0:\n",
        "                  if e[3] != 9:\n",
        "                    if (e[4] % 12) not in cho:\n",
        "                      cho.append(e[4] % 12)\n",
        "                else:\n",
        "                  if len(cho) > 0:\n",
        "                    chords.append(sorted(cho))\n",
        "                  cho = []\n",
        "                  if e[3] != 9:\n",
        "                    if (e[4] % 12) not in cho:\n",
        "                      cho.append(e[4] % 12)\n",
        "\n",
        "                pe = e\n",
        "                \n",
        "            if len(cho) > 0:\n",
        "                chords.append(sorted(cho))\n",
        "\n",
        "            ms_chords_counts = sorted([[list(key), val] for key,val in Counter([tuple(c) for c in chords if len(c) > 1]).most_common()], reverse=True, key = lambda x: x[1])\n",
        "            if len(ms_chords_counts) == 0:\n",
        "                ms_chords_counts = [[[0, 0], 0]]\n",
        "                \n",
        "            total_number_of_chords = len(set([y[1] for y in events_matrix1]))\n",
        "                \n",
        "            tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])\n",
        "            \n",
        "            thirty_second_note = [e for e in events_matrix1][32]\n",
        "            thirty_second_note_idx = full_events_matrix.index(thirty_second_note)\n",
        "\n",
        "            data = []\n",
        "            data.append(['total_number_of_tracks', itrack])\n",
        "            data.append(['total_number_of_opus_midi_events', len(opus_events_matrix)])\n",
        "            data.append(['total_number_of_score_midi_events', len(full_events_matrix)])\n",
        "            data.append(['average_median_mode_time_ms', [avg_time, median_time, mode_time]])\n",
        "            data.append(['average_median_mode_dur_ms', [avg_dur, median_dur, mode_dur]])\n",
        "            data.append(['average_median_mode_vel', [avg_vel, median_vel, mode_vel]])\n",
        "            data.append(['total_number_of_chords', total_number_of_chords])\n",
        "            data.append(['total_number_of_chords_ms', len(times)])\n",
        "            data.append(['ms_chords_counts', ms_chords_counts])\n",
        "            data.append(['pitches_times_sum_ms', times_sum])\n",
        "            data.append(['total_pitches_counts', pitches_counts])\n",
        "            data.append(['midi_patches', midi_patches])\n",
        "            data.append(['total_patches_counts', patches_counts])\n",
        "            data.append(['tempo_change_count', tempo_change_count])\n",
        "            data.append(['text_events_count', text_events_count])\n",
        "            data.append(['lyric_events_count', lyric_events_count])\n",
        "            data.append(['midi_ticks', score[0]])\n",
        "            data.extend(full_events_matrix[:thirty_second_note_idx])\n",
        "            data.append(full_events_matrix[-1])\n",
        "            \n",
        "            melody_chords_f.append([fn1, data])\n",
        "\n",
        "            #=======================================================\n",
        "\n",
        "            # Processed files counter\n",
        "            files_count += 1\n",
        "\n",
        "            # Saving every 5000 processed files\n",
        "            if files_count % 10000 == 0:\n",
        "              print('SAVING !!!')\n",
        "              print('=' * 70)\n",
        "              print('Saving processed files...')\n",
        "              print('=' * 70)\n",
        "              print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
        "              print('=' * 70)\n",
        "              count = str(files_count)\n",
        "              TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/LAMD_META_DATA_'+count)\n",
        "              melody_chords_f = []\n",
        "              print('=' * 70)\n",
        "\n",
        "    except KeyboardInterrupt:\n",
        "        print('Saving current progress and quitting...')\n",
        "        break  \n",
        "\n",
        "    except Exception as ex:\n",
        "        print('WARNING !!!')\n",
        "        print('=' * 70)\n",
        "        print('Bad MIDI:', f)\n",
        "        print('Error detected:', ex)\n",
        "        print('=' * 70)\n",
        "        continue\n",
        "\n",
        "# Saving last processed files...\n",
        "print('=' * 70)\n",
        "print('Saving processed files...')\n",
        "print('=' * 70)\n",
        "print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
        "print('=' * 70)\n",
        "count = str(files_count)\n",
        "TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/LAMD_META_DATA_'+count)\n",
        "\n",
        "# Displaying resulting processing stats...\n",
        "print('=' * 70)\n",
        "print('Done!')   \n",
        "print('=' * 70)\n",
        "\n",
        "print('Resulting Stats:')\n",
        "print('=' * 70)\n",
        "print('Total good processed MIDI files:', files_count)\n",
        "print('=' * 70)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# (BUILD FINAL METADATA FILE)"
      ],
      "metadata": {
        "id": "rr1IA9GwAybn"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Build final metadata file\n",
        "full_path_to_metadata_pickle_files = \"/content/drive/MyDrive\" #@param {type:\"string\"}\n",
        "\n",
        "print('=' * 70)\n",
        "print('Los Angeles MIDI Dataset Metadata File Builder')\n",
        "print('=' * 70)\n",
        "print('Searching for files...')\n",
        "\n",
        "filez = list()\n",
        "for (dirpath, dirnames, filenames) in os.walk(full_path_to_metadata_pickle_files):\n",
        "    filez += [os.path.join(dirpath, file) for file in filenames if file.split('.')[-1] == 'pickle']\n",
        "print('=' * 70)\n",
        "\n",
        "filez.sort()\n",
        "\n",
        "print('Loading metadata files... Please wait...')\n",
        "print('=' * 70)\n",
        "\n",
        "metadata = []\n",
        "\n",
        "for f in tqdm(filez):\n",
        "\n",
        "    metadata.extend(pickle.load(open(f, 'rb')))\n",
        "    print('Done!')\n",
        "    print('=' * 70)\n",
        "    print('Loaded file:', f)\n",
        "    print('=' * 70)\n",
        "  \n",
        "print('Done!')\n",
        "print('=' * 70)\n",
        "print('Randomizing metadata entries order...')\n",
        "random.shuffle(metadata)\n",
        "print('=' * 70)\n",
        "print('Writing final metadata pickle file...Please wait...')\n",
        "\n",
        "with open('/content/LAMDa_META_DATA.pickle', 'wb') as handle:\n",
        "  pickle.dump(metadata, handle, protocol=pickle.HIGHEST_PROTOCOL)\n",
        "\n",
        "print('=' * 70)\n",
        "print('Done!')\n",
        "print('=' * 70)"
      ],
      "metadata": {
        "cellView": "form",
        "id": "_uGS9wJGBoEF"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Zip final metadata file\n",
        "print('=' * 70)\n",
        "print('Zipping... Please wait...')\n",
        "print('=' * 70)\n",
        "!zip LAMDa_META_DATA.zip LAMDa_META_DATA.pickle\n",
        "print('=' * 70)\n",
        "print('Done!')\n",
        "print('=' * 70)"
      ],
      "metadata": {
        "cellView": "form",
        "id": "tnEgu3uYEX0a"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YzCMd94Tu_gz"
      },
      "source": [
        "# Congrats! You did it! :)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "machine_shape": "hm",
      "private_outputs": true,
      "provenance": []
    },
    "gpuClass": "standard",
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}