Upload inference.py with huggingface_hub
Browse files2 unmodified lines34567861 unmodified lines7071727374757677787980818283848586878889909192939495969798992 unmodified linesimport cv2import osimport numpy as npparser = argparse.ArgumentParser(description='Run model inference on images.')parser.add_argument('input_dir', type=str, help='Directory containing images for inference.')61 unmodified linesreturn warpedfor img_path in image_paths:img = cv2.imread(img_path)height, width = img.shape[:2]card = np.ones((height+100, width+100, 3), dtype=np.uint8) * 255card[50:50+height, 50:50+width] = imgcv2.imwrite(f"debug/{os.path.basename(img_path)}", card)if img is None and verbose>=1:print(f"Could not read image: {img_path}")continueresults = model.predict(source=img,save=False,conf=0.25,imgsz=416)rotated = crop_image_from_prediction(card, results[0])if rotated is None and verbose>=1:print(f"Could not rotate image: {img_path}")continuetry:cv2.imwrite(f"{save_dir}/{os.path.basename(img_path)}", rotated)except Exception as e:if verbose>=1:print(f"Error saving image {img_path} to {save_dir}: {e}")continueif verbose==2:print(f"Processed {img_path}, saved to {save_dir}/{os.path.basename(img_path)}")2 unmodified lines345678961 unmodified lines71727374757677787980818283848586878889909192939495969798991001011021031041051062 unmodified linesimport cv2import osimport numpy as npfrom tqdm import tqdmparser = argparse.ArgumentParser(description='Run model inference on images.')parser.add_argument('input_dir', type=str, help='Directory containing images for inference.')61 unmodified linesreturn warpedprogress = tqdm(total=len(image_paths), desc="Processing images", unit="image")for img_path in image_paths:img = cv2.imread(img_path)height, width = img.shape[:2]card = np.ones((height+50, width+50, 3), dtype=np.uint8) * 255card[50:50+height, 50:50+width] = imgcv2.imwrite(f"debug/{os.path.basename(img_path)}", card)if img is None and verbose>=1:print(f"Could not read image: {img_path}")progress.update(1)continueresults = model.predict(source=img,save=False,conf=0.25,imgsz=416,verbose=verbose==2)rotated = crop_image_from_prediction(card, results[0])if rotated is None and verbose>=1:print(f"Could not rotate image: {img_path}")progress.update(1)continuetry:cv2.imwrite(f"{save_dir}/{os.path.basename(img_path)}", rotated)except Exception as e:if verbose>=1:print(f"Error saving image {img_path} to {save_dir}: {e}")progress.update(1)continueif verbose==2:print(f"Processed {img_path}, saved to {save_dir}/{os.path.basename(img_path)}")progress.update(1)
inference.py+10-3