ulvis.paste.net

Paste Search Dynamic
Recent pastes
tensorflow
  1. import csv
  2. import tensorflow as tf
  3. import numpy as np
  4.  
  5. file = Path(cs_list[110]) # "data/receipts/","3b21dedf-5f5d-49c4-922f-bf212fd88cd3.csv")#
  6.  
  7. image_raw_data = tf.io.read_file(str(file.with_suffix(".jpeg")),'rb')
  8. #np.genfromtxt(path_to_csv, dtype=float, delimiter=',', names=True)
  9.  
  10. with open(str(file), newline='') as csvfile:
  11.     reader = csv.reader(csvfile)
  12.     next(reader, none)
  13.     bo= np.array(  [ [row[1],row[0],int(row[1])+int(row[3]),int(row[0])+int(row[2])] for row in reader], dtype=int  )
  14.    
  15. #with tf.Session() as sess:
  16. img_data = tf.image.decode_image(image_raw_data)
  17. img_data = tf.image.convert_image_dtype(img_data, tf.float32)
  18. dd = np.tile( img_data.shape[:2], 2)
  19. print (dd)
  20. print (img_data.shape)
  21.  
  22. boxes = [bo/ np.array(dd) ]
  23.  
  24. colors = tf.constant([[1.0,0,0,0], [0,1.0,0,0]])
  25. batched = tf.expand_dims(img_data, 0)
  26. image_with_box = tf.image.draw_bounding_boxes(batched, boxes, colors=colors)
  27. #print (image_with_box[0].eval())
  28. plt.imshow(image_with_box[0].numpy()),plt.title("result")
  29. plt.show()
  30.  
  31.  
  32. # data augmentation
  33. begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
  34.         tf.shape(img_data),
  35.         bounding_boxes=boxes,
  36.         min_object_covered=1,
  37.         use_image_if_no_bounding_boxes=false)
  38.  
  39. # #.html Draw the bounding box in an image summary.
  40. image_with_box = tf.image.draw_bounding_boxes(batched,#tf.expand_dims(img_data, 0),
  41.                                                bbox_for_draw, colors=colors)
  42. # tf.summary.image('images_with_box', image_with_box)
  43.  
  44. #.html Employ the bounding box to distort the image.
  45. distorted_image = tf.slice(img_data, begin, size)
  46. image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(distorted_image, 0),
  47.                                                bbox_for_draw, colors=colors)
  48.  
  49. plt.imshow(image_with_box[0].numpy()),plt.title("result")
  50. plt.show()
  51. print (bbox_for_draw)
Parsed in 0.024 seconds