mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-06-07 01:44:28 +08:00
Instancediffusion updates
This commit is contained in:
parent
8ccc080bf4
commit
5208980fc9
@ -687,8 +687,8 @@ bounding boxes.
|
|||||||
|
|
||||||
class CreateInstanceDiffusionTracking:
|
class CreateInstanceDiffusionTracking:
|
||||||
|
|
||||||
RETURN_TYPES = ("TRACKING", "INT", "INT", "INT", "INT",)
|
RETURN_TYPES = ("TRACKING", "STRING", "INT", "INT", "INT", "INT",)
|
||||||
RETURN_NAMES = ("tracking", "width", "height", "bbox_width", "bbox_height",)
|
RETURN_NAMES = ("tracking", "prompt", "width", "height", "bbox_width", "bbox_height",)
|
||||||
FUNCTION = "tracking"
|
FUNCTION = "tracking"
|
||||||
CATEGORY = "KJNodes/experimental"
|
CATEGORY = "KJNodes/experimental"
|
||||||
DESCRIPTION = """
|
DESCRIPTION = """
|
||||||
@ -712,50 +712,61 @@ for example:
|
|||||||
"bbox_height": ("INT", {"default": 512,"min": 16, "max": 4096, "step": 1}),
|
"bbox_height": ("INT", {"default": 512,"min": 16, "max": 4096, "step": 1}),
|
||||||
"class_name": ("STRING", {"default": "class_name"}),
|
"class_name": ("STRING", {"default": "class_name"}),
|
||||||
"class_id": ("INT", {"default": 0,"min": 0, "max": 255, "step": 1}),
|
"class_id": ("INT", {"default": 0,"min": 0, "max": 255, "step": 1}),
|
||||||
|
"prompt": ("STRING", {"default": "prompt", "multiline": True}),
|
||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"size_multiplier": ("FLOAT", {"default": [1.0], "forceInput": True}),
|
"size_multiplier": ("FLOAT", {"default": [1.0], "forceInput": True}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def tracking(self, coordinates, class_name, class_id, width, height, bbox_width, bbox_height, size_multiplier=[1.0]):
|
def tracking(self, coordinates, class_name, class_id, width, height, bbox_width, bbox_height, prompt, size_multiplier=[1.0]):
|
||||||
# Define the number of images in the batch
|
# Define the number of images in the batch
|
||||||
coordinates = coordinates.replace("'", '"')
|
coordinates = coordinates.replace("'", '"')
|
||||||
coordinates = json.loads(coordinates)
|
coordinates = json.loads(coordinates)
|
||||||
|
|
||||||
tracked = {}
|
tracked = {}
|
||||||
tracked[class_name] = {}
|
tracked[class_name] = {}
|
||||||
|
batch_size = len(coordinates)
|
||||||
# Initialize a list to hold the coordinates for the current ID
|
# Initialize a list to hold the coordinates for the current ID
|
||||||
id_coordinates = []
|
id_coordinates = []
|
||||||
|
if len(size_multiplier) != batch_size:
|
||||||
for coord in coordinates:
|
size_multiplier = size_multiplier * (batch_size // len(size_multiplier)) + size_multiplier[:batch_size % len(size_multiplier)]
|
||||||
|
for i, coord in enumerate(coordinates):
|
||||||
x = coord['x']
|
x = coord['x']
|
||||||
y = coord['y']
|
y = coord['y']
|
||||||
|
adjusted_bbox_width = bbox_width * size_multiplier[i]
|
||||||
|
adjusted_bbox_height = bbox_height * size_multiplier[i]
|
||||||
# Calculate the top left and bottom right coordinates
|
# Calculate the top left and bottom right coordinates
|
||||||
top_left_x = x - bbox_width // 2
|
top_left_x = x - adjusted_bbox_width // 2
|
||||||
top_left_y = y - bbox_height // 2
|
top_left_y = y - adjusted_bbox_height // 2
|
||||||
bottom_right_x = x + bbox_width // 2
|
bottom_right_x = x + adjusted_bbox_width // 2
|
||||||
bottom_right_y = y + bbox_height // 2
|
bottom_right_y = y + adjusted_bbox_height // 2
|
||||||
|
|
||||||
# Append the top left and bottom right coordinates to the list for the current ID
|
# Append the top left and bottom right coordinates to the list for the current ID
|
||||||
id_coordinates.append([top_left_x, top_left_y, bottom_right_x, bottom_right_y, width, height])
|
id_coordinates.append([top_left_x, top_left_y, bottom_right_x, bottom_right_y, width, height])
|
||||||
|
|
||||||
# Append the 'x' and 'y' coordinates along with bbox width/height and frame width/height to the list for the current ID
|
|
||||||
#id_coordinates.append([coord['x'] - bbox_width // 2 , coord['y'] - bbox_height // 2, bbox_width, bbox_height, width, height])
|
|
||||||
|
|
||||||
class_id = int(class_id)
|
class_id = int(class_id)
|
||||||
print(class_id)
|
|
||||||
# Assign the list of coordinates to the specified ID within the class_id dictionary
|
# Assign the list of coordinates to the specified ID within the class_id dictionary
|
||||||
tracked[class_name][class_id] = id_coordinates
|
tracked[class_name][class_id] = id_coordinates
|
||||||
print(tracked)
|
|
||||||
|
|
||||||
return (tracked, width, height, bbox_width, bbox_height,)
|
prompt_string = ""
|
||||||
|
for class_name, class_data in tracked.items():
|
||||||
|
for class_id in class_data.keys():
|
||||||
|
class_id_str = str(class_id)
|
||||||
|
# Use the incoming prompt for each class name and ID
|
||||||
|
prompt_string += f'"{class_id_str}.{class_name}": "({prompt})",\n'
|
||||||
|
|
||||||
|
# Remove the last comma and newline
|
||||||
|
prompt_string = prompt_string.rstrip(",\n")
|
||||||
|
|
||||||
|
print(prompt_string)
|
||||||
|
|
||||||
|
return (tracked, prompt_string, width, height, bbox_width, bbox_height)
|
||||||
|
|
||||||
class AppendInstanceDiffusionTracking:
|
class AppendInstanceDiffusionTracking:
|
||||||
|
|
||||||
RETURN_TYPES = ("TRACKING",)
|
RETURN_TYPES = ("TRACKING", "STRING",)
|
||||||
RETURN_NAMES = ("tracking",)
|
RETURN_NAMES = ("tracking", "prompt",)
|
||||||
FUNCTION = "append"
|
FUNCTION = "append"
|
||||||
CATEGORY = "KJNodes/experimental"
|
CATEGORY = "KJNodes/experimental"
|
||||||
DESCRIPTION = """
|
DESCRIPTION = """
|
||||||
@ -771,20 +782,24 @@ https://github.com/logtd/ComfyUI-InstanceDiffusion
|
|||||||
"tracking_1": ("TRACKING", {"forceInput": True}),
|
"tracking_1": ("TRACKING", {"forceInput": True}),
|
||||||
"tracking_2": ("TRACKING", {"forceInput": True}),
|
"tracking_2": ("TRACKING", {"forceInput": True}),
|
||||||
},
|
},
|
||||||
|
"optional": {
|
||||||
|
"prompt_1": ("STRING", {"default": "", "forceInput": True}),
|
||||||
|
"prompt_2": ("STRING", {"default": "", "forceInput": True}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def append(self, tracking_1, tracking_2):
|
def append(self, tracking_1, tracking_2, prompt_1="", prompt_2=""):
|
||||||
tracking_copy = tracking_1.copy()
|
tracking_copy = tracking_1.copy()
|
||||||
# Check for existing class names and class IDs, and raise an error if they exist
|
# Check for existing class names and class IDs, and raise an error if they exist
|
||||||
for class_name, class_data in tracking_2.items():
|
for class_name, class_data in tracking_2.items():
|
||||||
if class_name in tracking_copy:
|
if class_name not in tracking_copy:
|
||||||
for class_id in class_data.keys():
|
tracking_copy[class_name] = class_data
|
||||||
if class_id in tracking_copy[class_name]:
|
else:
|
||||||
raise ValueError(f"Class ID {class_id} already exists for class name {class_name}. Cannot append tracking data.")
|
# If the class name exists, merge the class data from tracking_2 into tracking_copy
|
||||||
# If class name does not exist, add it
|
# This will add new class IDs under the same class name without raising an error
|
||||||
tracking_copy[class_name] = class_data
|
tracking_copy[class_name].update(class_data)
|
||||||
|
prompt_string = prompt_1 + "," + prompt_2
|
||||||
return (tracking_copy, )
|
return (tracking_copy, prompt_string)
|
||||||
|
|
||||||
class InterpolateCoords:
|
class InterpolateCoords:
|
||||||
|
|
||||||
|
|||||||
@ -314,12 +314,19 @@ function createSplineEditor(context, reset=false) {
|
|||||||
var pointsLayer = null;
|
var pointsLayer = null;
|
||||||
var samplingMethod = samplingMethodWidget.value
|
var samplingMethod = samplingMethodWidget.value
|
||||||
|
|
||||||
|
if (samplingMethod == "path") {
|
||||||
|
dotShape = "triangle"
|
||||||
|
}
|
||||||
|
|
||||||
interpolationWidget.callback = () => {
|
interpolationWidget.callback = () => {
|
||||||
interpolation = interpolationWidget.value
|
interpolation = interpolationWidget.value
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
samplingMethodWidget.callback = () => {
|
samplingMethodWidget.callback = () => {
|
||||||
samplingMethod = samplingMethodWidget.value
|
samplingMethod = samplingMethodWidget.value
|
||||||
|
if (samplingMethod == "path") {
|
||||||
|
dotShape = "triangle"
|
||||||
|
}
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
tensionWidget.callback = () => {
|
tensionWidget.callback = () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user