-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Elastic Deformation for KPL #163
Comments
Some starters in python. https://gist.github.com/fmder/e28813c1e8721830ff9c import numpy as np
from scipy.ndimage.interpolation import map_coordinates
from scipy.ndimage.filters import gaussian_filter
def elastic_transform(image, alpha, sigma, random_state=None):
if random_state is None:
random_state = np.random.RandomState(None)
shape = image.shape
dx = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha
dy = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha
dz = np.zeros_like(dx)
x, y, z = np.meshgrid(np.arange(shape[1]), np.arange(shape[0]), np.arange(shape[2]))
indices = np.reshape(y+dy, (-1, 1)), np.reshape(x+dx, (-1, 1)), np.reshape(z, (-1, 1))
distored_image = map_coordinates(image, indices, order=1, mode='reflect')
return distored_image.reshape(image.shape) img = cv2.imread('sample.png')[:,:,::-1]
out = elastic_transform(img, alpha=1000, sigma=7) |
@innat is there a style guide or API method guide in which i should implement this feature to? Like an overall API architecture design? I hope to follow up on this and look into what i can do about this after my midterms, after 2-3 days. @bhack mentioned to like at tensorflow_addons implementation. It can't be as simple as reimplementing it to KerasCV API right? |
I'm not sure what you're looking for. For style guide or API method guide, is this sufficient? For implementation references, you can follow the following reference implementation.
|
I was just thinking if there are any strict coding style I should follow or any KerasCV API design pattern i should keep in mind during implementing the different object classes and methods. I think this is perfect ! I'll be proactive, keep being curious and continue to communicate ~ |
Hello, I recently posted an issue on tensorflow addons: tensorflow/addons#2733 I created a repo containing and explaining a working implementation of the catmull-rom (quite similar to Lanczos-2) interpolation as well as a comparison and a test It behaves just like dense_image_warp.py but uses a better interpolation scheme. I have no idea if it is up to the standards of these repositories. I use it in my research, and it works well enough. |
@Luvideria I didn't try |
I am not 100% sure. My use case is not elastic deformation but motion vector reprojection. Earlier @bhack mentionned dense_image_warp which may or may not make fully sense for the specific use case of this thread. I think that the dense_image can help with the last stage of elastic deformation. Dense_image_warp needs a list of sample points, which means the transform has to be computed by other means. Inside dense_image_warp it's like this: # flatten the input list
interpolated = interpolate_catmull_rom(image, query_points_flattened)
interpolated = tf.reshape(interpolated, [batch_size, height, width, channels]) It's just a list of sample points. In any case, I think that this dense image warp with catmull rom (or higher order, and not necessarily my implementation) deserves to be integrated in one way or another. I can eventually post this somewhere else where you deem it appropriate. I already mentioned it in tensorflow_addons: tensorflow/addons#2733 |
If we see tensorlayer https://tensorlayer.readthedocs.io/en/v2.2.4/_modules/tensorlayer/prepro.html#elastic_transform @Luvideria Probably you could open a new ticket in this repo for porting/refactoring the Then we could use it for build up the Elastic Deformation (as Tensorlayer done with scipy |
@Tony363 @Luvideria https://github.com/hirune924/imgaug-tf/blob/main/imgaugtf/augmentations.py#L253-L269 |
@Luvideria |
done |
This issue is stale because it has been open for 180 days with no activity. It will be closed if no further activity occurs. Thank you. |
Thanks for reporting the issue! We have consolidated the development of KerasCV into the new KerasHub package, which supports image, text, and multi-modal models. Please read keras-team/keras-hub#1831. KerasHub will support all the core functionality of KerasCV. KerasHub can be installed with !pip install -U keras-hub. Documentation and guides are available at keras.io/keras_hub. With our focus shifted to KerasHub, we are not planning any further development or releases in KerasCV. If you encounter a KerasCV feature that is missing from KerasHub, or would like to propose an addition to the library, please file an issue with KerasHub. |
This type of augmentation is mostly sued in 2D and 3D image augmentation, especially in medical imaging.
TensorFlow (DeepMind): How to use the On-the-Fly Elastic Deformation for TensorFlow
The text was updated successfully, but these errors were encountered: