-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Large scale controlnet #260
Changes from 8 commits
dee7044
17f9d97
dbb0506
fd08055
6640adb
87178fc
2d5b82a
de25828
1644fc3
4e81f55
7ead951
400d1b7
858701e
b3856c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,15 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
def convert_to_rgb(seg: np.array): | ||
def convert_to_rgb(seg: np.array) -> bytes: | ||
""" | ||
Converts a 2D segmentation to a RGB one which makes it possible to visualize it. | ||
|
||
Args: | ||
seg: 2D segmentation map as a NumPy array. | ||
|
||
Returns: | ||
color_seg: 3D segmentation map contain RGB values for each pixel. | ||
color_seg: the RGB segmentation map as a binary string | ||
""" | ||
color_seg = np.zeros( | ||
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8, | ||
|
@@ -32,9 +32,13 @@ def convert_to_rgb(seg: np.array): | |
for label, color in enumerate(palette): | ||
color_seg[seg == label, :] = color | ||
|
||
color_seg = color_seg.astype(np.uint8).tobytes() | ||
color_seg = color_seg.astype(np.uint8) | ||
image = Image.fromarray(color_seg).convert('RGB') | ||
|
||
return color_seg | ||
crop_bytes = io.BytesIO() | ||
image.save(crop_bytes, format="JPEG") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually save the image to disk? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this just saves it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok makes sense, thanks! |
||
|
||
return crop_bytes.getvalue() | ||
|
||
|
||
def process_image(image: bytes, *, processor: SegformerImageProcessor, device: str) -> torch.Tensor: | ||
|
@@ -46,6 +50,7 @@ def process_image(image: bytes, *, processor: SegformerImageProcessor, device: s | |
processor: The processor object for transforming the image. | ||
device: The device to move the transformed image to. | ||
""" | ||
|
||
def load(img: bytes) -> Image: | ||
"""Load the bytestring as an image.""" | ||
bytes_ = io.BytesIO(img) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,7 @@ consumes: | |
segmentations: | ||
fields: | ||
data: | ||
type: array | ||
items: | ||
type: binary | ||
type: binary | ||
|
||
args: | ||
hf_token: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like the main.py script has a default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defaults defined here translate internally to defaults defined in the argparser since kfp always requires a given provided argument if specified and cannot be empty.
The values defined in the argument parser generally take precedence over the default values defined in the main.py file so adding them there can be a bit misleading (e.g. if the user attempts to change them, the default values won't be used).