Advertisement
Guest User

LoadTFDataset

a guest
Nov 18th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. AUTOTUNE = tf.data.experimental.AUTOTUNE
  2.  
  3. def __get__tag__data():
  4.     with open("instances_train2017.json") as f:
  5.         listDick = json.load(f)
  6.  
  7.     images = listDick["images"]
  8.     annotations = listDick["annotations"]
  9.  
  10.     fileNames = [] // Name Of Files
  11.     catIDs = [] // Category IDS
  12.  
  13.     // Try And Load 10 Images For Now [ O(N^2) ]
  14.     for i in images[:10]:
  15.         fileNames.append(i["file_name"])
  16.         for j in annotations:
  17.             if(i["id"] == j["image_id"]):
  18.                 catIDs.append(j["category_id"])
  19.                 break // Break Once You Have Found
  20.  
  21.     print(fileNames) // Print And See If The List Looks Good
  22.     print(catIDs) // Prints And See If List Looks Good
  23.  
  24.     list_ds = tf.data.Dataset.from_tensor_slices((fileNames, catIDs)) // Make A Tuple Of The 2 Arrays And Load Into a TF Dataset
  25.  
  26.     // Print And See If Tensors Are Being Inputted Correctly
  27.     for f in list_ds.take(5):
  28.         print(f)
  29.  
  30.     # Set `num_parallel_calls` so multiple images are loaded/processed in parallel.
  31.     labeled_ds = list_ds.map(process_img_label, num_parallel_calls=AUTOTUNE)
  32.     print(labeled_ds)
  33.  
  34.     thing = labeled_ds.take(1)
  35.     print(thing)
  36.  
  37.     for image, label in labeled_ds.take(1): // ERROR HAPPENS HERE!!!
  38.         print("Image shape: ", image.numpy().shape)
  39.         print("Label: ", label.numpy())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement