YaTharThShaRma999 commited on
Commit
cfb3a93
·
1 Parent(s): acc4474

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +43 -22
README.md CHANGED
@@ -1,27 +1,48 @@
1
- ---
2
- license: mit
3
- ---
4
- git clone https://github.com/cliport/cliport.git
5
- from susie.model import create_sample_fn
6
- from susie.jax_utils import initialize_compilation_cache
7
- import requests
8
  import numpy as np
9
- from PIL import Image
10
- https://github.com/cliport/cliport/releases/download/v1.0.0/cliport_quickstart.zip
11
- initialize_compilation_cache()
 
12
 
13
- IMAGE_URL = "https://rail.eecs.berkeley.edu/datasets/bridge_release/raw/bridge_data_v2/datacol2_toykitchen7/drawer_pnp/01/2023-04-19_09-18-15/raw/traj_group0/traj0/images0/im_12.jpg"
14
 
15
- sample_fn = create_sample_fn("kvablack/susie")
16
- image = np.array(Image.open(requests.get(IMAGE_URL, stream=True).raw).resize((256, 256)))
17
- image_out = sample_fn(image, "open the drawer")
18
 
19
- # to display the images if you're in a Jupyter notebook
20
- display(Image.fromarray(image))
21
- display(Image.fromarray(image_out))
 
 
 
 
 
 
22
 
23
- https://github.com/kvablack/susie/tree/8177f63332a3905202c122310a92c51b8ff14280
24
- 2nd one
25
- Imagine you are a human, how would you break these visual tasks down to step by step?I will give you a task, some objects and you must break them down step by step, each step should be roughly 5 words but correct.
26
- Task: clean the window with the sponge and then put it down in the table
27
- Objects: Window, table, sponge near table
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from itertools import product, chain
2
+ import math
3
+ import matplotlib.pyplot as plt
 
 
 
 
4
  import numpy as np
5
+ import networkx as nx
6
+ import cv2
7
+ im = cv2.imread("/kaggle/working/black.png")
8
+ im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
9
 
10
+ h, w = im.shape # Get height and width of image
11
 
12
+ # Add only those nodes which are black to graph
13
+ nodes = [(i, j) for (i, j) in product(range(h), range(w)) if im[i, j] == 0]
14
+ g = nx.Graph(nodes)
15
 
16
+ # For each node there can be 8 neighbours, if you consider diagonal as well.
17
+ def get_neighbors(node):
18
+ box_coords = product([-1, 0, 1], [-1, 0, 1])
19
+ nns = []
20
+ for coord in box_coords:
21
+ if coord[0] != coord[1]:
22
+ nn = (node[0] - coord[0], node[1] - coord[1])
23
+ nns.append(nn)
24
+ return nns
25
 
26
+ # A point will be a neighbour if it is black as well and is in image bounds
27
+ neighbors = list(chain.from_iterable([[(node, ng_node, 1) for ng_node in get_neighbors(node) if (im[node] == 0) and (0 < ng_node[0] < h) and (0 < ng_node[1] , w)] for node in nodes]))
28
+
29
+ g.add_weighted_edges_from(neighbors)
30
+
31
+ # In image loaded above (0, 0) is top left point. To keep things little more generic. I select point closest to (0, 0) as start and furthest as end.
32
+
33
+ min_pt = min(nodes, key=lambda x: math.hypot(x[0], x[1]))
34
+ max_pt = max(nodes, key=lambda x: math.hypot(x[0], x[1]))
35
+
36
+ # Now we can just use networkx to find path between two points
37
+ path = nx.shortest_path(g, source=min_pt, target=max_pt)
38
+
39
+ # Get new image with only shortest path
40
+ im2 = 255*np.ones_like(im)
41
+ # Draw the path on the original image before saving
42
+ # Draw the path on the original image with white color
43
+ for i in range(len(path)-1):
44
+ cv2.line(im, path[i], path[i+1], color=(255), thickness=1)
45
+
46
+ cv2.imwrite('image_with_path.png', im)
47
+ plt.figure(figsize=(10, 10))
48
+ plt.imshow(im, cmap='gray')