<jupyter_start><jupyter_text>inference<jupyter_code>import cv2
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from cellpose import models, io, plot

def rle_encode(img):
    pixels = img.flatten()
    pixels = np.concatenate([[0], pixels, [0]])
    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1
    runs[1::2] -= runs[::2]
    return ' '.join(str(x) for x in runs)

test_dir = "../input/sartorius-cell-instance-segmentation/test/"
test_img_dirs = [test_dir + i for i in os.listdir(test_dir)]


test_imgs = []
for i in test_img_dirs:
    img = cv2.imread(i,cv2.IMREAD_COLOR)
    test_imgs.append(img)

    
model = models.CellposeModel(gpu=True, pretrained_model="/kaggle/working/cell/train/models/cellpose_residual_on_style_on_concatenation_off_train_2021_12_12_04_27_47.649538", torch=True, diam_mean=30.0, net_avg=True, device=None, residual_on=True, style_on=True, concatenation=False)
masks_all = []
styles_all = []
flows_all = []


for img in test_imgs:
    chan = [0,0] # for black and white imgs
    #img = io.imread(filename)
    masks, flows, styles = model.eval(img, diameter=60, channels=chan)

    masks_all.append(masks)
    flows_all.append(flows)
    styles_all.append(styles)

# DISPLAY RESULTS

    fig = plt.figure(figsize=(12,5))
    plot.show_segmentation(fig, img, masks, flows[0], channels=chan)
    plt.tight_layout()
    plt.show()


#model = models.Cellpose(gpu=False, model_type='cyto')
#model = models.Cellpose(gpu=True, model_type='cyto')<jupyter_output>parsing model string to get cellpose options
** TORCH CUDA version installed and working. **
>>>> using GPU
time spent: running network 0.04s; flow+mask computation 0.20
{'fraction_non_alphanumeric': 0.13341274568195355, 'fraction_numerical': 0.029184038117927337, 'mean_word_length': 4.793103448275862, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '482593', 'license': 'MIT', 'n_tokens_mistral': 655, 'n_tokens_neox': 630, 'n_words': 131, 'path': 'train/model-training-cellpose.ipynb', 'repo_name': 'soumya997/kaggle-Sartorius-Experimentations', 'size': '1679'}