zsylvester / segmenteverygrain Goto Github PK
View Code? Open in Web Editor NEWA SAM-based model for instance segmentation of images of grains
License: Apache License 2.0
A SAM-based model for instance segmentation of images of grains
License: Apache License 2.0
Hi zsylvester, wanted to say thank you for the great package!
Came across an issue I am struggling to fix when using the Segment_every_grain notebook. The following error pops up using the code here:
n_of_units = 10 # centimeters in this case units_per_pixel = n_of_units/dist
`---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [36], in <cell line: 2>()
1 n_of_units = 10 # centimeters in this case
----> 2 units_per_pixel = n_of_units/dist
NameError: name 'dist' is not defined`
I was wondering what is the best way to fix this?
Hi @zsylvester ,
Thank you! The colab notebook works great, two small changes removes the errors from it.
all_grains, labels, mask_all, grain_data, fig, ax = seg.sam_segmentation(sam, big_im, big_im_pred, coords, labels, min_area=50.0)
In cell 12 (or so, might be off by 1) the outputs from the function sam_segmentation needed to be updated.
all_grains, labels, mask_all, fig, ax = seg.get_grains_from_patches(ax, big_im)
Same here, around cell 17 (again, might be off by 1)
Let le know if this works for you.
Cheers,
Thomas
cc: @zanejobe
Hello, thanks for the repo! Any chance I can train/finetune the model without resorting to creating patches?
When I was using the latest TensorFlow, there was an error in the code, which seems to be caused by incompatible versions. Could you provide the version of the package.
I get the following error code while using code in google collab:
ValueError: You are trying to restore a checkpoint from a legacy Keras optimizer into a v2.11+ Optimizer, which can cause errors. Please update the optimizer referenced in your code to be an instance of tf.keras.optimizers.legacy.Optimizer
, e.g.: tf.keras.optimizers.legacy.Adam
.
Tried both instances with no solution to the problem.
The code used is shown below:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import cv2
from skimage import measure
from tensorflow.keras.optimizers.legacy import Adam
from tensorflow.keras.preprocessing.image import load_img
from importlib import reload
import segmenteverygrain as seg
from tqdm import trange
import tensorflow as tf
model = seg.Unet()
model.compile(optimizer= "Adam", loss=seg.weighted_crossentropy, metrics=["accuracy"])
model.load_weights('./checkpoints/seg_model')
The very last line "model.load_weights" is where the error is and not sure how to approach it.
Would your algorithm be appropriate for counting stars?
Thanks
Nice to meet you. Thanks for such a great model.
I am trying to run Segment_every_grain.ipynb
on VScode.
I rewrote part of the contents of the distributed Segment_every_grain.ipynb
(see attached photo), and when I ran it, I got a "ValueError: attempt to get argmax of an empty sequence sequence" in "Run segmentation".
I would like to know the solution.
*I am using Google Translate.
Environment
・Mac book pro14 (M1pro)
・VScode(anaconda)
・Python(3.12.2)
・library list (see attached photo)
hi,
I have ran the example scripts both in Jupyter and in Colab and getting the same error. Have previously ran it fine so might be related to an update or package update. It does plot the figure but does not return all_grains, labels, mask_all etc...
IndexError Traceback (most recent call last)
in <cell line: 7>()
5 # decreasing the 'dbs_max_dist' parameter results in more SAM prompts (and longer processing times):
6 labels, grains, coords = seg.label_grains(big_im, big_im_pred, dbs_max_dist=10.0)
----> 7 all_grains, labels, mask_all, grain_data, fig, ax = seg.sam_segmentation(sam, big_im, big_im_pred, coords, labels, min_area=50.0)
1 frames
/usr/local/lib/python3.10/dist-packages/segmenteverygrain/segmenteverygrain.py in plot_grain_axes_and_centroids(all_grains, labels, ax, linewidth, markersize)
763 regions = regionprops(labels.astype('int'))
764 for ind in range(len(all_grains)-1):
--> 765 y0, x0 = regions[ind].centroid
766 orientation = regions[ind].orientation
767 x1 = x0 + np.cos(orientation) * 0.5 * regions[ind].minor_axis_length
IndexError: list index out of range
May I ask that how the gravel_example_mask.jpg
was generated?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.