Traceback (most recent call last): File "/home/cyl/.conda/envs/cosypose/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/cyl/.conda/envs/cosypose/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/cyl/cosypose/cosypose/scripts/run_cosypose_eval.py", line 491, in <module> main() File "/home/cyl/cosypose/cosypose/scripts/run_cosypose_eval.py", line 332, in main scene_ds = make_scene_dataset(ds_name) File "/home/cyl/cosypose/cosypose/datasets/datasets_cfg.py", line 68, in make_scene_dataset ids.append(np.where(mask)[0].item()) ValueError: can only convert an array of size 1 to a Python scalar
添加debug输出,得到
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Debug - scene_id: 48, view_id: 1 Debug - mask matches: 1 Debug - where result shape: (1,), values: [225] Debug - scene_id: 48, view_id: 36 Debug - mask matches: 1 Debug - where result shape: (1,), values: [226] Debug - scene_id: 48, view_id: 47 Debug - mask matches: 1 Debug - where result shape: (1,), values: [227] Debug - scene_id: 48, view_id: 83 Debug - mask matches: 1 Debug - where result shape: (1,), values: [228] Debug - scene_id: 48, view_id: 112 Debug - mask matches: 1 Debug - where result shape: (1,), values: [229] Debug - scene_id: 48, view_id: 135 Debug - mask matches: 0 Debug - where result shape: (0,), values: [] 0:00:00.912023 - Expected exactly one match, got 0 matches for scene_id=48, view_id=135
from http import HTTPStatus from dashscope import Generation from dashscope.api_entities.dashscope_response import Role
defconversation_with_messages(): messages = [{'role': Role.SYSTEM, 'content': 'You are a helpful assistant.'}, {'role': Role.USER, 'content': '如何做西红柿炖牛腩?'}] response = Generation.call( Generation.Models.qwen_turbo, messages=messages, # set the result to be "message" format. result_format='message', ) if response.status_code == HTTPStatus.OK: print(response) # append result to messages. messages.append({'role': response.output.choices[0]['message']['role'], 'content': response.output.choices[0]['message']['content']}) else: print('Request id: %s, Status code: %s, error code: %s, error message: %s' % ( response.request_id, response.status_code, response.code, response.message )) messages.append({'role': Role.USER, 'content': '不放糖可以吗?'}) # make second round call response = Generation.call( Generation.Models.qwen_turbo, messages=messages, result_format='message', # set the result to be "message" format. ) if response.status_code == HTTPStatus.OK: print(response) else: print('Request id: %s, Status code: %s, error code: %s, error message: %s' % ( response.request_id, response.status_code, response.code, response.message ))
if __name__ == '__main__': conversation_with_messages()
写成notebook形式
基本的包以及api-key指定:
1 2 3 4 5 6 7
from http import HTTPStatus from dashscope import Generation from dashscope.aigc.generation import Message from dashscope.api_entities.dashscope_response import Role import dashscope
dashscope.api_key = "..."
创建初始message:
1
messages = [Message(Role.SYSTEM, 'you are a cyl家的小女仆口牙')]
提问#1:
1 2 3 4 5 6 7
messages.append(Message(Role.USER, 'how to install archlinux')) response = Generation.call( Generation.Models.qwen_turbo, messages=messages, # set the result to be "message" format. result_format='message', )
1
response
1
GenerationResponse(status_code=<HTTPStatus.OK: 200>, request_id='dcf58c98-17c0-95fd-80c1-3f88fc8dd9db', code='', message='', output=GenerationOutput(text=None, choices=[Choice(finish_reason='stop', message=Message({'role': 'assistant', 'content': 'Installing Arch Linux can be done in several steps, ... Remember to read the Arch Linux documentation for further guidance and troubleshooting: [https://wiki.archlinux.org/](https://wiki.archlinux.org/)'}))], finish_reason=None), usage=GenerationUsage(input_tokens=24, output_tokens=687))
from http import HTTPStatus from dashscope import Generation from dashscope.aigc.generation import Message from dashscope.api_entities.dashscope_response import Role import dashscope
defask(question:str): messages.append(Message(Role.USER, question)) response = Generation.call( Generation.Models.qwen_turbo, messages=messages, # set the result to be "message" format. result_format='message', ) if response.status_code == HTTPStatus.OK: messages.append(Message(response.output.choices[0]['message']['role'], response.output.choices[0]['message']['content'])) else: pass
if __name__ == '__main__': setup("你是陈语林家的可爱小女仆呀") ask("你是谁呀") print(messages[-1]) ask("你知道些什么") print(messages[-1])
This will extract the top 20 categories from the ‘category’ column of the DataFrame and create a new DataFrame that only includes rows with those categories.
Posted Updated a few seconds read (About 81 words)
Extracting room numbers from a ‘Description’ column in a DataFrame using regular expressions:
Import the re module:
1 2 3 4 5 6 7 8 9 10 11 12
import re ````
2. Define a function to extract the room number from a description:
```python defextract_room_number(description): match = re.search(r'(\d+\.\d+|\d+)(?=\s+of which are bedrooms)', description) ifmatch: returnfloat(match.group(1)) else: returnNone
Use the apply() method to apply the function to the ‘Description’ column and create a new ‘RoomNumber’ column: