object detection and image classification using pretrained ai modelsfrom tensorflow.keras.applications import MobileNetV2 from tensorflow.keras.applications.mobilenet_v2 import preprocess_input, decode_predictions from tensorflow.keras.preprocessing import image import numpy as np #Load pretrained model model = MobileNetV2(weights='imagenet') #Load and preprocess image img = image.load_img('image.jpg', target_size=(224, 224)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) x = preprocess_input(x) #Predict and decode results preds = model.predict(x) print('Predicted:', decode_predictions(preds, top=3)[0]) pip install tensorflow pillow numpy pip install opencv-python numpy pip install matplotlib scipy imutils python 3.10.x scene understanding and image segmentation using foundation modelsfrom transformers import CLIPSegProcessor, CLIPSegForImageSegmentation from PIL import Image import torch import matplotlib.pyplot as plt #Load pretrained model processor = CLIPSegProcessor.from_pretrained("CIDAS/clipseg-rd64-refined") model = CLIPSegForImageSegmentation.from_pretrained("CIDAS/clipseg-rd64-refined") #Load your image image = Image.open("scene.jpg") # put your image in same folder prompt = ["person"] # what you want to segment #Process and predict inputs = processor(text=prompt, images=image, return_tensors="pt") with torch.no_grad(): outputs = model(**inputs) mask = torch.sigmoid(outputs.logits)[0][0].numpy() #Show result plt.imshow(image) plt.imshow(mask, alpha=0.5, cmap="jet") plt.title("Segmented: " + prompt[0]) plt.axis("off") plt.show() pip install torch torchvision transformers pillow matplotlib |