User trying to import a module that's not installed. Instead of bumping him and telling her to use a different workspace on which the module *is* installed, use compute resources to try and install.. nuts.. Starting with : from transformers import TFAutoModelForSeq2SeqLM, AutoTokenizer import gradio as gr model = TFAutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small") tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small") def gen_text(input_string, max_length): inputs = tokenizer(input_string, return_tensors="pt") outputs = model.generate(**inputs, max_length=max_length) final_text = tokenizer.batch_decode(outputs[0], skip_special_tokens=True) return (final_text) demo = gr.Interface( fn=gen_text, ...
The free openCV crash course :
img_NZ_bgr = cv.imread('New_Zealand_Lake.jpg', cv.IMREAD_COLOR)
b,g,r = cv.split(img_NZ_bgr)
plt.figure(figsize=[20,5])
plt.subplot(141);plt.imshow(r, cmap='gray');plt.title("Red")
plt.subplot(142);plt.imshow(b, cmap='gray');plt.title("Blue")
plt.subplot(143);plt.imshow(g, cmap='gray');plt.title("Green")
# merging
imgMerged = cv.merge((b,g,r)) # original code : b,g,r
plt.subplot(144);plt.imshow(imgMerged[...,::-1]);plt.title("Merged")
Gives you :
Coolie McVoolie. But, wait a minute! Are you really going to fall for that? Remember those "3D" glasses you got in magazines as a kid that let you see the page in 3D by using filters (each eye sees the picture from the required angle)? Meaning, if you're looking at the Red channel, you want to see :
This!
Right?
How? Easy
- Make a blank channel (basically using NumPy zeros)
- Use that blank channel for the filtered channels, and use cv.merge, rather than one channel by itself. (NOTE, cv is really cv2 IYDAK😊)
So, let's have fun :
blk = np.zeros([600,840], dtype=np.uint8) # by default gives you float64 which cv2.merge hates
plt.figure(figsize=[20,5])
imgMerged = cv.merge((blk,blk,r)) # original code : b,g,r
plt.subplot(141);plt.imshow(imgMerged[...,::-1]);plt.title("Red")
imgMerged = cv.merge((blk,g,blk))
plt.subplot(142);plt.imshow(imgMerged[...,::-1]);plt.title("Green")
imgMerged = cv.merge((b,blk,blk))
plt.subplot(143);plt.imshow(imgMerged[...,::-1]);plt.title("Blue")
# merging
imgMerged = cv.merge((b,g,r)) # original code : b,g,r
plt.subplot(144);plt.imshow(imgMerged[...,::-1]);plt.title("Merged")
And you get :
Tell me, is that fun or what?😊The classic Ballard and Brown Computer Vision textbook - online for free : https://homepages.inf.ed.ac.uk/rbf/BOOKS/BANDB/toc.htm
Comments
Post a Comment