<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Natdhanai Praneenatthavee on Medium]]></title>
        <description><![CDATA[Stories by Natdhanai Praneenatthavee on Medium]]></description>
        <link>https://medium.com/@spped2000?source=rss-47208b7dc832------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xqDYOJv9wyT4WYXd-BrKSg.jpeg</url>
            <title>Stories by Natdhanai Praneenatthavee on Medium</title>
            <link>https://medium.com/@spped2000?source=rss-47208b7dc832------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 19:17:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@spped2000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Inside vLLM Meetup Bangkok: Why This World-Class AI Project is the GitHub Darling of 2025]]></title>
            <link>https://medium.com/@spped2000/inside-vllm-meetup-bangkok-why-this-world-class-ai-project-is-the-github-darling-of-2025-951b8ab6696e?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/951b8ab6696e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[lmcache]]></category>
            <category><![CDATA[vllm]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 15:35:16 GMT</pubDate>
            <atom:updated>2025-11-30T15:35:17.742Z</atom:updated>
            <content:encoded><![CDATA[<p>On November 21, 2025, I had the opportunity to attend the vLLM Meetup Bangkok. While the evening atmosphere was casual and friendly, the content shared on stage was absolutely &quot;blazing hot.&quot; This event brought together top-tier minds in LLM Serving and Inference Optimization.</p><p>Today, I want to share my experience and recap the key takeaways. We’ll explore why vLLM has secured its spot as a Top Open Source Project on GitHub in 2025, and why new features like Sleep Mode and LMCache are absolute game-changers for developers.<br>​(Note: Although there were various sessions at the event, this article will focus specifically on the highlights from the vLLM presentation.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ajtx5AlCop0bLZTFwcg54Q.jpeg" /></figure><h3>1. The Crown Jewel of Open Source 2025</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K4KN_CuMuiUqZ4nEkb8xzw.jpeg" /></figure><p>It wasn’t just hype—vLLM has officially been recognized as a top open-source project this year. The secret to its massive adoption lies in its versatility:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lRMBqExkkM3evV7ffI7CVA.jpeg" /></figure><ul><li>​Hardware Agnostic: It runs on almost anything. Whether you are on &quot;Team Green&quot; (NVIDIA), &quot;Team Red&quot; (AMD), Intel, Google TPU, or even just running locally on Mac OS, vLLM has you covered.</li><li>​Model Agnostic: Whenever a new model drops—be it Llama, DeepSeek, Mistral, or Qwen—vLLM provides support almost immediately (often on Day 1).</li></ul><h3>2. &quot;Sleep Mode&quot;: Solving the Inference Pain Point</h3><p>If you have ever tried running multiple models on limited GPU resources, you know the struggle is real. Unloading an old model to load a new one takes time—often minutes—creating a terrible user experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxpxCp7-X1qyJzMugpfGlw.jpeg" /></figure><p>vLLM V1 introduces &quot;Zero-Reload Model Switching&quot; (a.k.a. Sleep Mode), and it is brilliant:</p><ul><li>​Idle State: When no one is using the model, it enters &quot;Sleep Mode,&quot; dropping VRAM usage to just 10%.</li><li>​Instant Wake-up: As soon as a request comes in, the model &quot;wakes up&quot; and is ready for the next prompt immediately.</li><li>​The Impact: This eliminates the agonizing 30-100 second reload time, saving both time and computational resources.</li></ul><h3>3. Meet &quot;LMCache&quot;: The New Speed Standard</h3><p>Another major highlight was the introduction of LMCache. The speakers claimed this is becoming the new De-Facto Standard for KV Cache management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXsJbyydtpfqXEqTwD4GdA.jpeg" /></figure><ul><li>The Problem: The longer the conversation (Long Context), the faster your memory fills up, causing the system to lag.</li><li>The Solution: LMCache intelligently &quot;offloads&quot; the cache you aren’t currently using to other storage (like Disk or Network/Cloud) rather than clogging up your GPU memory.</li><li>The Result: It improves Time to First Token (TTFT) by 5-10x!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*40Qd0P27qyT95hh-HdRA2w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3Z_z8Wn2SDtBjjG0t9XcQ.jpeg" /></figure><p>​The benchmark graphs shown at the event were undeniable. The combination of vLLM + LMCache leaves competitors in the dust, making it the perfect solution for Enterprises that need to support massive concurrent user bases.</p><h3>​Final Thoughts</h3><p>If you missed the event, don’t worry! You can check out the code, documentation, and try the demos directly on the vLLM and LMCache GitHub repositories.</p><p>​One thing is clear after this meetup: The world of AI Infrastructure is evolving rapidly, and there are plenty of exciting developments ahead!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bWjtzZIPm9A8MkH9E9flAg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iyMBuAHWqUkEOlGIfz7CNA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=951b8ab6696e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gemini File Search Part 1: Introduction]]></title>
            <link>https://medium.com/@spped2000/gemini-file-search-part-1-introduction-8fde4468a5ce?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fde4468a5ce</guid>
            <category><![CDATA[embedding]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[filesearch]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Sun, 09 Nov 2025 18:03:09 GMT</pubDate>
            <atom:updated>2025-11-09T18:03:09.376Z</atom:updated>
            <content:encoded><![CDATA[<p>Google ได้เปิดตัวอัปเดตใหม่ชื่อ <strong>File Search</strong> ซึ่งช่วยให้นักพัฒนาแอป AI ที่ใช้ Gemini API สามารถสร้างระบบ RAG (Retrieval-Augmented Generation) ได้ง่ายขึ้นอย่างมากครับ มาดูกันว่าน่าสนใจยังไง</p><p>แบบเดิม: การสร้าง RAG มีความซับซ้อนและต้องจัดการ 6 ส่วนหลัก:</p><p>1. Data Loader — อ่านไฟล์ข้อมูล</p><p>2. Text Splitter — แบ่งข้อความเป็นชิ้นเล็ก (chunking)</p><p>3. Embedding Model — แปลงข้อความเป็น vectors</p><p>4. Vector Database — เก็บ vectors</p><p>5. Retrieval Logic — สืบค้นข้อมูลจาก database</p><p>6. Orchestration Layer — ประสานงานระหว่าง query, retrieval และ model</p><h3>แบบใหม่ (ด้วย File Search):</h3><ul><li>เครื่องมือ <strong>File Search </strong>ได้รวบ 5 ขั้นตอนแรก (การโหลด, แบ่ง, embedding, จัดเก็บ, ดึงข้อมูล) มาจัดการให้ทั้งหมด</li><li>นักพัฒนาไม่จำเป็นต้องตั้งค่าหรือจัดการฐานข้อมูล Vector Database แยกต่างหากอีกต่อไป</li><li>File Search จะทำการนำเข้าไฟล์, chunking, และทำ indexing ข้อมูลให้โดยอัตโนมัติ</li><li>ข้อมูลที่ถูกจัดทำ index นี้จะถูกนำไปใช้เป็นบริบท (context) ให้กับโมเดล Gemini โดยตรงครับ ทำให้โมเดลสามารถให้คำตอบที่แม่นยำและเกี่ยวข้องกับข้อมูลในไฟล์นั้นๆ ได้ดียิ่งขึ้นมากๆ</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vXzq_DOSrbKnefLDFMSqlw.jpeg" /><figcaption><a href="https://ai.google.dev/gemini-api/docs/file-search?fbclid=IwY2xjawN9tWNleHRuA2FlbQIxMABicmlkETEwODNBSlp6ZDFZNkFEb3VEc3J0YwZhcHBfaWQQMjIyMDM5MTc4ODIwMDg5MgABHju8zZbH4EIwYuz1OsQcgWtDG1Zv38Hd19dBNGV9Zjr45WHR4QIERf8s-2_7_aem_B7r7nR0vBsNOBEetbVtGGg&amp;brid=8zNsIA7Q4YvQjTgv9FA12A">File Search architecture</a></figcaption></figure><h3>สำหรับเพื่อนๆที่อยากลงรายละเอียดเชิงลึก</h3><p>จุดเด่นที่น่าสนใจ:</p><p><strong>1: Chunking Configuration แบบ Custom</strong></p><p>ปรับแต่งการแบ่ง chunk ได้เอง:</p><pre>max_tokens_per_chunk: กำหนดขนาด chunk สูงสุด (เช่น 200 tokens)<br>max_overlap_tokens: กำหนด overlap ระหว่าง chunks (เช่น 20 tokens)<br>&#39;chunking_config&#39;: {<br>    &#39;white_space_config&#39;: {<br>        &#39;max_tokens_per_chunk&#39;: 200,<br>        &#39;max_overlap_tokens&#39;: 20<br>    }<br>}</pre><p><strong>2: File Metadata &amp; Filtering</strong></p><p>เพิ่ม metadata ให้กับไฟล์เพื่อ filter ข้อมูลได้แม่นยำ:</p><pre>custom_metadata=[<br>    {&quot;key&quot;: &quot;author&quot;, &quot;string_value&quot;: &quot;Robert Graves&quot;},<br>    {&quot;key&quot;: &quot;year&quot;, &quot;numeric_value&quot;: 1934}<br>]</pre><p>Filter เฉพาะเอกสารที่ต้องการ</p><pre>metadata_filter = &#39;author=Robert Graves&#39;</pre><p>Use Case: เมื่อมีหลายเอกสารใน store เดียวกัน สามารถค้นหาเฉพาะกลุ่มที่ต้องการได้</p><p><strong>3: Citations &amp; Grounding Metadata</strong></p><p>รู้แหล่งที่มาของคำตอบ — เหมาะสำหรับ fact-checking:</p><pre>print(response.candidates[0].grounding_metadata)</pre><p>ระบบจะบอกว่าคำตอบมาจากส่วนไหนของเอกสาร</p><p><strong>4: File Search Store Management</strong></p><p>Raw file ใน File API จะถูกลบหลัง 48 ชั่วโมง</p><p>แต่ข้อมูลใน File Search Store จะถูปเก็บไว้ตลอด ไม่มีวันหมดอายุ จนกว่าจะลบเอง</p><p>สร้างหลาย stores เพื่อจัดระเบียบเอกสารได้</p><p>ตั้งชื่อ display_name เพื่อความสะดวกในการจัดการ</p><p><strong>5: รองรับไฟล์หลากหลายชนิด</strong></p><p>100+ file types รวมถึง:</p><p>Documents: PDF, DOCX, XLSX, PPTX, TXT</p><p>Code: Python, JavaScript, Java, C++, SQL, PHP</p><p>Data: JSON, CSV, XML, YAML</p><p>Markup: Markdown, HTML, LaTeX</p><p><strong>6: Models ที่รองรับ</strong></p><p>ใช้ได้กับทุก Gemini models รุ่นล่าสุด</p><h3>ราคา (Pricing)</h3><p>- Indexing: $0.15 ต่อ 1M tokens (ตอน embed ครั้งแรก)</p><p>- Storage: ฟรี!</p><p>- Query time embeddings: ฟรี!</p><p>- Retrieved tokens: คิดเป็น context tokens ปกติ</p><p>Storage Limits ตาม Tier:</p><p>Free: 1 GB</p><p>Tier 1: 10 GB</p><p>Tier 2: 100 GB</p><p>Tier 3: 1 TB</p><p>Recommendation: แต่ละ store ไม่ควรเกิน 20 GB เพื่อความเร็วที่ดีที่สุดครับ</p><p>Rate Limits</p><p>ไฟล์สูงสุด: 100 MB/ไฟล์</p><p>File search stores ต่อ project: 10 stores</p><h3>สรุป</h3><p>Google File Search ทำให้การสร้าง RAG application:</p><p>1. ง่ายขึ้นมาก — ไม่ต้องจัดการ infrastructure เอง</p><p>2. ฟรี storage — ประหยัดต้นทุน</p><p>3. ยืดหยุ่น — ปรับแต่ง chunking และ metadata ได้</p><p>4. Fact checking — มี citations บอกแหล่งที่มา</p><p>5. รองรับครบ — 100+ file types</p><p>ให้ developer โฟกัสที่การสร้าง features แทนการจัดการ vector database ครับบ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fde4468a5ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pydantic AI คืออะไร? และทำไมมันสำคัญกับ AI ในยุคนี้]]></title>
            <link>https://medium.com/@spped2000/pydantic-ai-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%97%E0%B8%B3%E0%B9%84%E0%B8%A1%E0%B8%A1%E0%B8%B1%E0%B8%99%E0%B8%AA%E0%B8%B3%E0%B8%84%E0%B8%B1%E0%B8%8D%E0%B8%81%E0%B8%B1%E0%B8%9A-ai-%E0%B9%83%E0%B8%99%E0%B8%A2%E0%B8%B8%E0%B8%84%E0%B8%99%E0%B8%B5%E0%B9%89-62ca152c900a?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/62ca152c900a</guid>
            <category><![CDATA[pydantic]]></category>
            <category><![CDATA[multi-agent-systems]]></category>
            <category><![CDATA[safety]]></category>
            <category><![CDATA[weather]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 12:38:11 GMT</pubDate>
            <atom:updated>2025-03-07T12:46:26.971Z</atom:updated>
            <content:encoded><![CDATA[<p>Pydantic AI เป็นเครื่องมือที่ช่วยให้การพัฒนา AI มีความแม่นยำ และ ปลอดภัยขึ้น</p><p>และยังทำ Agetic-AI ได้อีกด้วย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z9GfkzUDOMJzeQfPNgNeiA.png" /><figcaption><a href="https://github.com/pydantic/pydantic-ai">PydanticAI</a></figcaption></figure><h3>🔥 ทำไม Pydantic AI ถึงสำคัญ? (อธิบายง่ายๆ)</h3><p>ลองนึกภาพว่าเรามี <strong>Chatbot AI</strong> ที่ใช้ช่วยตอบคำถามลูกค้าในร้านค้าออนไลน์ เช่น <strong>Shopee, Lazada หรือร้านค้าผ่าน LINE OA</strong></p><p>🛒 <strong>ตัวอย่าง</strong>:<br>ลูกค้าส่งข้อความว่า</p><blockquote><strong><em>“ขอราคากาแฟสดแพ็กใหญ่</em></strong><em>”</em></blockquote><p><strong>Chatbot </strong>ของเราส่งไปยังโมเดล AI แต่ดันได้คำตอบกลับมาแบบนี้:</p><blockquote><strong><em>“ราคาของคุณคือ 1,000,000 บาท”</em></strong></blockquote><p>🤯 <strong>เกิดอะไรขึ้น?</strong></p><ul><li>AI ตอบมั่ว เพราะได้รับข้อมูลผิดพลาด (เช่น ระบบแปลงราคาผิด)</li><li>ลูกค้าตกใจ คิดว่าร้านโกง!</li><li>ร้านเสียความน่าเชื่อถือ</li></ul><p>✅ วิธีแก้ไข: <strong>ใช้ Pydantic AI เพื่อตรวจสอบข้อมูลก่อนส่งให้ AI</strong></p><p>คราวนี้ลองมาดูการใช้งานกันดูแบบ basic กันก่อน</p><pre>from pydantic import BaseModel, PositiveFloat<br><br>class ProductQuery(BaseModel):<br>    product_name: str<br>    max_price: PositiveFloat<br><br># ข้อมูลถูกต้องตามเงื่อนไขที่กำหนด<br>query = ProductQuery(product_name=&quot;กาแฟสด&quot;, max_price=1000.0)<br>print(query)<br><br># output<br># product_name=&#39;กาแฟสด&#39; max_price=1000.0</pre><p>โดย ผมก็ได้กำหนด<strong> type</strong> ของ <strong>product_name </strong>และของ<strong> max_price</strong> โดยต้องเป็น <strong>String </strong>และ <strong>Positive Float</strong> ตามลำดับ</p><p>แต่ถ้าเกิดเหตุการณ์ที่ลูกค้า <strong>query </strong>ข้อมูลมาผิดอย่างตัวอย่างข้างล่าง ตัว <strong>Pydantic</strong> ก็จะเตือนออกมา</p><pre>query = ProductQuery(product_name=&quot;กาแฟสด&quot;, max_price=-500.0)</pre><p>ผลลัพธ์ที่ได้คือ</p><pre>---------------------------------------------------------------------------<br>ValidationError                           Traceback (most recent call last)<br>Cell In[4], line 1<br>----&gt; 1 query = ProductQuery(product_name=&quot;กาแฟสด&quot;, max_price=-500.0)<br><br>File /usr/local/lib/python3.10/dist-packages/pydantic/main.py:212, in BaseModel.__init__(self, **data)<br>    210 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks<br>    211 __tracebackhide__ = True<br>--&gt; 212 validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)<br>    213 if self is not validated_self:<br>    214     warnings.warn(<br>    215         &#39;A custom validator is returning a value other than `self`.\n&#39;<br>    216         &quot;Returning anything other than `self` from a top level model validator isn&#39;t supported when validating via `__init__`.\n&quot;<br>    217         &#39;See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.&#39;,<br>    218         category=None,<br>    219     )<br><br>ValidationError: 1 validation error for ProductQuery<br>max_price<br>  Input should be greater than 0 [type=greater_than, input_value=-500.0, input_type=float]<br>    For further information visit https://errors.pydantic.dev/2.9/v/greater_than</pre><p>จะเห็นว่ามันเตือนว่า type ผิดมันต้องเป็น <strong>positive float</strong> ไม่ใช่ <strong>negative float</strong></p><h3>คราวนี้เรามาลองการใช้ Pydantic AI แบบ Basic โดยการเชื่อมกับ LLMs ในบทความนี้เราจะใช้ตัว Gemini-1.5-flash</h3><ul><li>สาเหตุที่ใช้ Gemini เพราะว่าเราสามารถขอ api ได้ฟรี ผ่านทางเว็บ <a href="https://aistudio.google.com/app/apikey">Get API key | Google AI Studio</a></li><li>หลังจากที่เราได้ Gemini api key</li></ul><pre>import os<br><br>os.environ[&quot;GEMINI_API_KEY&quot;] = &quot;ํYour API KEY&quot;<br><br></pre><ul><li>คราวนี้เรามาลอง ใช้ Pydantic AI เบื้องต้นกัน</li></ul><pre>from pydantic_ai import Agent<br><br><br>agent = Agent(<br>    &#39;google-gla:gemini-1.5-flash&#39;,<br><br>    system_prompt=&#39;Be concise, reply with one sentence.&#39;,<br>)<br><br><br>result = agent.run_sync(&#39;Where is the capital of England&#39;)<br>print(result.data)<br># คำตอบที่ได้ The capital of England is London.</pre><p>ต่อไปผมจะมาสร้าง AI Agent ที่สามารถเชื่อมกับ API ภายนอกได้คราวนี้ผมจะสร้าง Weather AI ซึ่งจะเชื่อมกับ API สภาพอากาศถายนอกและถูมิประเทศ แบบ Real-time</p><ul><li>API weather สมัครและใช้งานได้ฟรีที่ <a href="https://www.tomorrow.io/weather-api/">https://www.tomorrow.io/weather-api/</a></li><li>API ด้านถูมิศาสตร์ สมัครและใช้งานได้ฟรีที่ <a href="https://geocode.maps.co/search">https://geocode.maps.co/search</a></li><li>โดยจะ กำหนดโครงสร้างและการตั้งค่าสำหรับตัว Agent ที่จะใช้เรียก API ข้อมูลสภาพอากาศ</li></ul><pre>@dataclass<br>class Deps:<br>    client: AsyncClient<br>    weather_api_key: str | None<br>    geo_api_key: str | None<br><br>weather_agent = Agent(<br>    &#39;google-gla:gemini-1.5-flash&#39;,<br>    # Register a static system prompt using a keyword argument to the agent.<br>    # For more complex dynamically-generated system prompts, see the example below.<br>    system_prompt=&#39;Be concise, reply with one sentence.&#39;,<br>    deps_type=Deps,<br>    retries=2,<br>)</pre><p>@dataclass class Deps เป็นการสร้างคลาสที่เก็บข้อมูลที่จำเป็นสำหรับการทำงานของ Agent โดยเก็บสิ่งต่อไปนี้:</p><ul><li>client: AsyncClient - ตัวไคลเอนต์ HTTP แบบAsyncสำหรับการเรียก API</li><li>weather_api_key: str | None - คีย์สำหรับเรียกใช้ API สภาพอากาศ</li><li>geo_api_key: str | None - คีย์สำหรับเรียกใช้ API ข้อมูลพิกัดทางภูมิศาสตร์</li></ul><p>weather_agent = Agent(...) เป็นการสร้างและกำหนดค่า Agent ที่จะจัดการการสนทนาและเรียกใช้เครื่องมือต่างๆ:</p><ul><li>ใช้โมเดล ‘google-gla:gemini-1.5-flash’ เป็น LLM หลัก</li><li>กำหนด system prompt ให้ตอบสั้นกระชับเพียงหนึ่งประโยค</li><li>ระบุว่า Agent นี้ต้องการ dependencies ตามที่กำหนดในคลาส Deps</li><li>ตั้งค่าให้ Agent สามารถลองใหม่ได้สูงสุด 2 ครั้งหากเกิดข้อผิดพลาด</li></ul><pre>@weather_agent.tool<br>async def get_lat_lng(<br>    ctx: RunContext[Deps], location_description: str<br>) -&gt; dict[str, float]:<br>    &quot;&quot;&quot;Get the latitude and longitude of a location.<br><br>    Args:<br>        ctx: The context.<br>        location_description: A description of a location.<br>    &quot;&quot;&quot;<br>    if ctx.deps.geo_api_key is None:<br>        return {&#39;lat&#39;: 51.1, &#39;lng&#39;: -0.1}<br><br>    params = {<br>        &#39;q&#39;: location_description,<br>        &#39;api_key&#39;: ctx.deps.geo_api_key,<br>    }<br>    with logfire.span(&#39;calling geocode API&#39;, params=params) as span:<br>        r = await ctx.deps.client.get(&#39;https://geocode.maps.co/search&#39;, params=params)<br>        r.raise_for_status()<br>        data = r.json()<br>        span.set_attribute(&#39;response&#39;, data)<br><br>    if data:<br>        return {&#39;lat&#39;: data[0][&#39;lat&#39;], &#39;lng&#39;: data[0][&#39;lon&#39;]}<br>    else:<br>        raise ModelRetry(&#39;Could not find the location&#39;)</pre><ul><li>decorator @weather_agent.tool ทำให้ LLM (Gemini model) สามารถเรียกใช้ฟังก์ชันนี้ได้เมื่อจำเป็นต้องแปลงชื่อสถานที่เป็นพิกัด</li><li>มี parameters function คือ ctx: RunContext[Deps] - การทำงานที่มี dependencies ที่จำเป็น เช่น HTTP client และ API keys และ location_description: str - ข้อความที่อธิบายสถานที่ เช่น &quot;Bangkok&quot; หรือ &quot;New Jersey&quot;</li><li>การตรวจสอบ API key</li></ul><pre>if ctx.deps.geo_api_key is None:<br>    return {&#39;lat&#39;: 51.1, &#39;lng&#39;: -0.1}</pre><p>ถ้าไม่มี API key สำหรับบริการข้อมูลพิกัด จะคืนค่าพิกัดค่าคงที่ (ซึ่งเป็นพิกัดของลอนดอนโดยประมาณ) เพื่อให้โปรแกรมยังทำงานได้โดยไม่มีข้อผิดพลาด</p><ul><li>การเรียกใช้ Geocoding API</li></ul><pre>params = {<br>    &#39;q&#39;: location_description,<br>    &#39;api_key&#39;: ctx.deps.geo_api_key,<br>}<br>with logfire.span(&#39;calling geocode API&#39;, params=params) as span:<br>    r = await ctx.deps.client.get(&#39;https://geocode.maps.co/search&#39;, params=params)<br>    r.raise_for_status()<br>    data = r.json()<br>    span.set_attribute(&#39;response&#39;, data)</pre><p>ส่วนนี้จะเรียกใช้ API ของ geocode.maps.co เพื่อค้นหาพิกัดของสถานที่ที่ระบุ โดย</p><ul><li>สร้างพารามิเตอร์สำหรับการค้นหา (คำค้นและ API key)</li><li>ใช้ logfire.span เพื่อบันทึกและติดตามการเรียก API (เป็นเครื่องมือสำหรับการ logging)</li><li>เรียก API แบบ async ด้วย await</li><li>ตรวจสอบสถานะการตอบกลับด้วย raise_for_status()</li><li>แปลงข้อมูล JSON ที่ได้รับกลับมา</li><li>บันทึกการตอบกลับลงใน span สำหรับการติดตาม</li></ul><p>การจัดการผลลัพธ์และข้อผิดพลาด</p><pre>if data:<br>    return {&#39;lat&#39;: data[0][&#39;lat&#39;], &#39;lng&#39;: data[0][&#39;lon&#39;]}<br>else:<br>    raise ModelRetry(&#39;Could not find the location&#39;)</pre><ul><li>ถ้าได้รับข้อมูลกลับมา จะคืนค่าพิกัดจากข้อมูลแรกที่พบ</li><li>ถ้าไม่พบข้อมูล จะยกเว้น ModelRetry ซึ่งบอก PydanticAI ว่าควรพยายามเรียกการทำงานใหม่ (อาจด้วยข้อมูลที่แตกต่าง)</li></ul><p>ฟังก์ชัน get_weather นี้เป็นเครื่องมือชิ้นที่สองของ weather agent ซึ่งทำหน้าที่ดึงข้อมูลสภาพอากาศจากพิกัดทางภูมิศาสตร์ที่ได้รับมา</p><pre>@weather_agent.tool<br>async def get_weather(ctx: RunContext[Deps], lat: float, lng: float) -&gt; dict[str, Any]:<br>    &quot;&quot;&quot;Get the weather at a location.<br><br>    Args:<br>        ctx: The context.<br>        lat: Latitude of the location.<br>        lng: Longitude of the location.<br>    &quot;&quot;&quot;<br>    if ctx.deps.weather_api_key is None:<br>        # if no API key is provided, return a dummy response<br>        return {&#39;temperature&#39;: &#39;21 °C&#39;, &#39;description&#39;: &#39;Sunny&#39;}<br><br>    params = {<br>        &#39;apikey&#39;: ctx.deps.weather_api_key,<br>        &#39;location&#39;: f&#39;{lat},{lng}&#39;,<br>        &#39;units&#39;: &#39;metric&#39;,<br>    }<br>    with logfire.span(&#39;calling weather API&#39;, params=params) as span:<br>        r = await ctx.deps.client.get(<br>            &#39;https://api.tomorrow.io/v4/weather/realtime&#39;, params=params<br>        )<br>        r.raise_for_status()<br>        data = r.json()<br>        span.set_attribute(&#39;response&#39;, data)<br><br>    values = data[&#39;data&#39;][&#39;values&#39;]<br>    code_lookup = {<br>        1000: &#39;Clear, Sunny&#39;,<br>        1100: &#39;Mostly Clear&#39;,<br>        1101: &#39;Partly Cloudy&#39;,<br>        1102: &#39;Mostly Cloudy&#39;,<br>        1001: &#39;Cloudy&#39;,<br>        2000: &#39;Fog&#39;,<br>        2100: &#39;Light Fog&#39;,<br>        4000: &#39;Drizzle&#39;,<br>        4001: &#39;Rain&#39;,<br>        4200: &#39;Light Rain&#39;,<br>        4201: &#39;Heavy Rain&#39;,<br>        5000: &#39;Snow&#39;,<br>        5001: &#39;Flurries&#39;,<br>        5100: &#39;Light Snow&#39;,<br>        5101: &#39;Heavy Snow&#39;,<br>        6000: &#39;Freezing Drizzle&#39;,<br>        6001: &#39;Freezing Rain&#39;,<br>        6200: &#39;Light Freezing Rain&#39;,<br>        6201: &#39;Heavy Freezing Rain&#39;,<br>        7000: &#39;Ice Pellets&#39;,<br>        7101: &#39;Heavy Ice Pellets&#39;,<br>        7102: &#39;Light Ice Pellets&#39;,<br>        8000: &#39;Thunderstorm&#39;,<br>    }<br>    return {<br>        &#39;temperature&#39;: f&#39;{values[&quot;temperatureApparent&quot;]:0.0f}°C&#39;,<br>        &#39;description&#39;: code_lookup.get(values[&#39;weatherCode&#39;], &#39;Unknown&#39;),<br>    }</pre><h4><strong>Parameters</strong></h4><ul><li>ctx: RunContext[Deps] - บริบทการทำงานที่มี dependencies ต่างๆ</li><li>lat: float - ค่าละติจูดของสถานที่ที่ต้องการดูสภาพอากาศ</li><li>lng: float - ค่าลองจิจูดของสถานที่ที่ต้องการดูสภาพอากาศ</li></ul><h4>การตรวจสอบ API key</h4><pre>if ctx.deps.weather_api_key is None:<br>    # if no API key is provided, return a dummy response<br>    return {&#39;temperature&#39;: &#39;21 °C&#39;, &#39;description&#39;: &#39;Sunny&#39;}</pre><p>เช่นเดียวกับฟังก์ชัน get_lat_lng ถ้าไม่มี API key สำหรับบริการข้อมูลสภาพอากาศ ฟังก์ชันจะคืนค่าข้อมูลจำลอง (dummy data) เพื่อให้โปรแกรมทำงานได้โดยไม่มีข้อผิดพลาด คือ อุณหภูมิ 21°C และท้องฟ้าแจ่มใส</p><h4>การเรียกใช้ Weather API</h4><pre>params = {<br>    &#39;apikey&#39;: ctx.deps.weather_api_key,<br>    &#39;location&#39;: f&#39;{lat},{lng}&#39;,<br>    &#39;units&#39;: &#39;metric&#39;,<br>}<br>with logfire.span(&#39;calling weather API&#39;, params=params) as span:<br>    r = await ctx.deps.client.get(<br>        &#39;https://api.tomorrow.io/v4/weather/realtime&#39;, params=params<br>    )<br>    r.raise_for_status()<br>    data = r.json()<br>    span.set_attribute(&#39;response&#39;, data)</pre><h4>การแปลงรหัสสภาพอากาศเป็นข้อความ</h4><p>Tomorrow.io API ส่งคืนรหัสตัวเลขที่แทนสภาพอากาศต่างๆ ฟังก์ชันนี้จึงมีพจนานุกรม code_lookup ที่แปลงรหัสเหล่านั้นให้เป็นข้อความที่ให้อ่านเข้าใจได้ เช่น:</p><ul><li>1000: ‘Clear, Sunny’ (ท้องฟ้าแจ่มใส, มีแดด)</li><li>4001: ‘Rain’ (ฝน)</li><li>8000: ‘Thunderstorm’ (พายุฝนฟ้าคะนอง)</li></ul><h4>การสร้างผลลัพธ์</h4><pre>return {<br>    &#39;temperature&#39;: f&#39;{values[&quot;temperatureApparent&quot;]:0.0f}°C&#39;,<br>    &#39;description&#39;: code_lookup.get(values[&#39;weatherCode&#39;], &#39;Unknown&#39;),<br>}</pre><ul><li>temperature - อุณหภูมิที่รู้สึกว่าเป็น (apparent temperature) จาก API ในรูปแบบองศาเซลเซียส โดยปัดเศษทศนิยมออก</li><li>description - คำอธิบายสภาพอากาศที่ได้จากการแปลงรหัสสภาพอากาศด้วย code_lookup หากไม่พบรหัสในพจนานุกรมจะแสดงเป็น &#39;Unknown&#39;</li></ul><pre>async def main():<br>    async with AsyncClient() as client:<br>        # create a free API key at https://www.tomorrow.io/weather-api/<br>        weather_api_key = os.getenv(&#39;WEATHER_API_KEY&#39;)<br>        # create a free API key at https://geocode.maps.co/<br>        geo_api_key = os.getenv(&#39;GEO_API_KEY&#39;)<br>        deps = Deps(<br>            client=client, weather_api_key=weather_api_key, geo_api_key=geo_api_key<br>        )<br>        result = await weather_agent.run(<br>            &#39;What is the weather like in Bangkok and in New Jersey?&#39;, deps=deps<br>        )<br>        debug(result)<br>        print(&#39;Response:&#39;, result.data)<br><br><br>if __name__ == &#39;__main__&#39;:<br>    asyncio.run(main())</pre><p>นี่คือหัวใจของโปรแกรม ในขั้นตอนนี้ จะเรียกใช้ weather_agent ซึ่งเป็น Agent ที่ได้กำหนดไว้ก่อนหน้านี้ โดย:</p><ol><li>ส่งคำถาม “What is the weather like in Bangkok and in New Jersey?” ให้ Agent</li><li>ส่ง dependencies (deps) ที่เตรียมไว้ให้ Agent ใช้งาน</li><li>ใช้ await เพื่อรอให้การทำงานเสร็จสมบูรณ์ เนื่องจากเป็นการทำงานแบบ async</li></ol><p>เมื่อเรียกใช้ ตัว Agent จะทำงานดังนี้:</p><ul><li>LLM (Gemini) วิเคราะห์คำถามและเข้าใจว่าต้องการสภาพอากาศของสองสถานที่</li><li>LLM เรียกใช้ get_lat_lng เพื่อแปลง &quot;Bangkok&quot; และ &quot;New Jersey&quot; เป็นพิกัด</li><li>จากนั้น LLM เรียกใช้ get_weather เพื่อดึงข้อมูลสภาพอากาศจากพิกัดที่ได้</li><li>LLM ประมวลผลข้อมูลและสร้างคำตอบที่กระชับตาม system prompt ที่กำหนดไว้</li></ul><h3>Result ที่ได้</h3><pre>16:03:52.619 weather_agent run prompt=What is the weather like in Bangkok and in New Jersey?<br>16:03:52.620   preparing model request params run_step=1<br>16:03:52.620   model request<br>16:03:53.449   handle model response<br>16:03:53.449     running tools=[&#39;get_lat_lng&#39;, &#39;get_lat_lng&#39;]<br>16:03:53.451     calling geocode API<br>16:03:53.452     calling geocode API<br>16:03:53.924   preparing model request params run_step=2<br>16:03:53.924   model request<br>16:03:54.667   handle model response<br>16:03:54.667     running tools=[&#39;get_weather&#39;]<br>16:03:54.667     calling weather API<br>16:03:55.158   preparing model request params run_step=3<br>16:03:55.159   model request<br>16:03:55.900   handle model response<br>16:03:55.902     running tools=[&#39;get_weather&#39;]<br>16:03:55.902     calling weather API<br>16:03:56.306   preparing model request params run_step=4<br>16:03:56.307   model request<br>16:03:56.996   handle model response<br>C:\Users\natdhanai.pra\AppData\Local\Temp\ipykernel_23824\277239959.py:147 main<br>    result: RunResult(<br>        _all_messages=[<br>            ModelRequest(<br>                parts=[<br>                    SystemPromptPart(<br>                        content=&#39;Be concise, reply with one sentence.&#39;,<br>                        dynamic_ref=None,<br>                        part_kind=&#39;system-prompt&#39;,<br>                    ),<br>                    UserPromptPart(<br>                        content=&#39;What is the weather like in Bangkok and in New Jersey?&#39;,<br>                        timestamp=datetime.datetime(2025, 2, 19, 16, 3, 52, 620746, tzinfo=datetime.timezone.utc),<br>                        part_kind=&#39;user-prompt&#39;,<br>                    ),<br>                ],<br>                kind=&#39;request&#39;,<br>            ),<br>            ModelResponse(<br>                parts=[<br>                    ToolCallPart(<br>                        tool_name=&#39;get_lat_lng&#39;,<br>                        args={<br>                            &#39;location_description&#39;: &#39;Bangkok&#39;,<br>                        },<br>                        tool_call_id=None,<br>                        part_kind=&#39;tool-call&#39;,<br>                    ),<br>                    ToolCallPart(<br>                        tool_name=&#39;get_lat_lng&#39;,<br>                        args={<br>                            &#39;location_description&#39;: &#39;New Jersey&#39;,<br>                        },<br>                        tool_call_id=None,<br>                        part_kind=&#39;tool-call&#39;,<br>                    ),<br>                ],<br>                model_name=&#39;gemini-1.5-flash&#39;,<br>                timestamp=datetime.datetime(2025, 2, 19, 16, 3, 53, 448510, tzinfo=datetime.timezone.utc),<br>                kind=&#39;response&#39;,<br>            ),<br>            ModelRequest(<br>                parts=[<br>                    ToolReturnPart(<br>                        tool_name=&#39;get_lat_lng&#39;,<br>                        content={<br>                            &#39;lat&#39;: &#39;13.7524938&#39;,<br>                            &#39;lng&#39;: &#39;100.4935089&#39;,<br>                        },<br>                        tool_call_id=None,<br>                        timestamp=datetime.datetime(2025, 2, 19, 16, 3, 53, 621934, tzinfo=datetime.timezone.utc),<br>                        part_kind=&#39;tool-return&#39;,<br>                    ),<br>                    ToolReturnPart(<br>                        tool_name=&#39;get_lat_lng&#39;,<br>                        content={<br>                            &#39;lat&#39;: &#39;40.0757384&#39;,<br>                            &#39;lng&#39;: &#39;-74.4041622&#39;,<br>                        },<br>                        tool_call_id=None,<br>                        timestamp=datetime.datetime(2025, 2, 19, 16, 3, 53, 923735, tzinfo=datetime.timezone.utc),<br>                        part_kind=&#39;tool-return&#39;,<br>                    ),<br>                ],<br>                kind=&#39;request&#39;,<br>            ),<br>            ModelResponse(<br>                parts=[<br>                    ToolCallPart(<br>                        tool_name=&#39;get_weather&#39;,<br>                        args={<br>                            &#39;lng&#39;: 100.4935089,<br>                            &#39;lat&#39;: 13.7524938,<br>                        },<br>                        tool_call_id=None,<br>                        part_kind=&#39;tool-call&#39;,<br>                    ),<br>                ],<br>                model_name=&#39;gemini-1.5-flash&#39;,<br>                timestamp=datetime.datetime(2025, 2, 19, 16, 3, 54, 666290, tzinfo=datetime.timezone.utc),<br>                kind=&#39;response&#39;,<br>            ),<br>            ModelRequest(<br>                parts=[<br>                    ToolReturnPart(<br>                        tool_name=&#39;get_weather&#39;,<br>                        content={<br>                            &#39;temperature&#39;: &#39;26°C&#39;,<br>                            &#39;description&#39;: &#39;Mostly Cloudy&#39;,<br>                        },<br>                        tool_call_id=None,<br>                        timestamp=datetime.datetime(2025, 2, 19, 16, 3, 55, 158621, tzinfo=datetime.timezone.utc),<br>                        part_kind=&#39;tool-return&#39;,<br>                    ),<br>                ],<br>                kind=&#39;request&#39;,<br>            ),<br>            ModelResponse(<br>                parts=[<br>                    ToolCallPart(<br>                        tool_name=&#39;get_weather&#39;,<br>                        args={<br>                            &#39;lat&#39;: 40.0757384,<br>                            &#39;lng&#39;: -74.4041622,<br>                        },<br>                        tool_call_id=None,<br>                        part_kind=&#39;tool-call&#39;,<br>                    ),<br>                ],<br>                model_name=&#39;gemini-1.5-flash&#39;,<br>                timestamp=datetime.datetime(2025, 2, 19, 16, 3, 55, 900501, tzinfo=datetime.timezone.utc),<br>                kind=&#39;response&#39;,<br>            ),<br>            ModelRequest(<br>                parts=[<br>                    ToolReturnPart(<br>                        tool_name=&#39;get_weather&#39;,<br>                        content={<br>                            &#39;temperature&#39;: &#39;-11°C&#39;,<br>                            &#39;description&#39;: &#39;Cloudy&#39;,<br>                        },<br>                        tool_call_id=None,<br>                        timestamp=datetime.datetime(2025, 2, 19, 16, 3, 56, 305321, tzinfo=datetime.timezone.utc),<br>                        part_kind=&#39;tool-return&#39;,<br>                    ),<br>                ],<br>                kind=&#39;request&#39;,<br>            ),<br>            ModelResponse(<br>                parts=[<br>                    TextPart(<br>                        content=&#39;In Bangkok it is mostly cloudy and 26°C, while in New Jersey it is cloudy and -11°C.\n&#39;,<br>                        part_kind=&#39;text&#39;,<br>                    ),<br>                ],<br>                model_name=&#39;gemini-1.5-flash&#39;,<br>                timestamp=datetime.datetime(2025, 2, 19, 16, 3, 56, 996152, tzinfo=datetime.timezone.utc),<br>                kind=&#39;response&#39;,<br>            ),<br>        ],<br>        _new_message_index=0,<br>        data=&#39;In Bangkok it is mostly cloudy and 26°C, while in New Jersey it is cloudy and -11°C.\n&#39;,<br>        _result_tool_name=None,<br>        _usage=Usage(<br>            requests=4,<br>            request_tokens=553,<br>            response_tokens=57,<br>            total_tokens=610,<br>            details=None,<br>        ),<br>    ) (RunResult)<br>Response: In Bangkok it is mostly cloudy and 26°C, while in New Jersey it is cloudy and -11°C.</pre><pre>Response: In Bangkok it is mostly cloudy and 26°C, while in New Jersey it is cloudy and -11°C.</pre><h3>สรุป</h3><p><strong>PydanticAI </strong>นำเสนอวิธีการใหม่ในการสร้าง <strong>Agents</strong> โดยผสมผสานกับ <strong>LLM</strong> Weather Agent ในตัวอย่างนี้แสดงให้เห็นว่าเราสามารถสร้าง <strong>Agents </strong>ที่ตอบคำถามเกี่ยวกับสภาพอากาศได้อย่างRealt-time และเก่งงโดยรู้ว่าต้องใช้เครื่องมือใดบ้างและในลำดับใด</p><p>จุดแข็งสำคัญของแนวทางนี้คือ เพียงแค่กำหนดว่า <strong>Agents</strong> “สามารถทำอะไรได้บ้าง” ผ่านการสร้างเครื่องมือ แต่ไม่ต้องกำหนดว่า “ต้องทำอะไรเมื่อใด” เพราะ LLM จะตัดสินใจเองได้ว่าควรเรียกใช้เครื่องมือใดเพื่อตอบคำถามที่ได้รับ ทำให้การพัฒนาระบบที่ซับซ้อนเป็นเรื่องง่ายขึ้น</p><h3>Reference</h3><p><a href="https://github.com/pydantic/pydantic-ai">pydantic/pydantic-ai: Agent Framework / shim to use Pydantic with LLMs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62ca152c900a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DeepSeekR1-Qwen2.5VL-Multi Modal-Agents ทำง่ายๆที่บ้าน เมื่อโมเดลจีนรวมพลังกันจะเกิดอะไรขึ้น]]></title>
            <link>https://medium.com/@spped2000/deepseekr1-qwen2-5vl-multi-modal-agents-%E0%B8%97%E0%B8%B3%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2%E0%B9%86%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%9A%E0%B9%89%E0%B8%B2%E0%B8%99-%E0%B9%80%E0%B8%A1%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B9%82%E0%B8%A1%E0%B9%80%E0%B8%94%E0%B8%A5%E0%B8%88%E0%B8%B5%E0%B8%99%E0%B8%A3%E0%B8%A7%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%B1%E0%B8%87%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B8%88%E0%B8%B0%E0%B9%80%E0%B8%81%E0%B8%B4%E0%B8%94%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99-df5d17be6d5b?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/df5d17be6d5b</guid>
            <category><![CDATA[multimodal]]></category>
            <category><![CDATA[deepseek]]></category>
            <category><![CDATA[qwen]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[agents]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 10:05:10 GMT</pubDate>
            <atom:updated>2025-02-03T10:05:10.358Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*Z4Dv52MZrd_vvATOWL4Zaw.png" /><figcaption>Moodengggg</figcaption></figure><h3><strong>DeepSeek และ Qwen เป็นที่พูดถึงกันมากในช่วงเวลานี้ วันนี้ผมจะมาทำ Demo โดยเอา Qwen2.5VL และ DeepSeek-R1 มาทำ Agent โดยใช้ SWARM</strong></h3><p>ที่จริงในโลกนี้มี Framework เกี่ยวกับ Agents หลายตัวที่น่าสนใจขึ้นอยู่กับลักษณะของงานที่ใช้และความถนัด ส่วนตัวผมชอบ SWARM เพราะผมชอบผึ้ง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*csbeYdjFofJe6o22.jpg" /><figcaption><a href="https://github.com/openai/swarm">SWARM — Source</a></figcaption></figure><p>ในบทความนี้อาจจะเป็นการลงลึกถึงพริกถึงขิงเกี่ยวกับการใช้งาน อาจจะไม่เหมาะกับผู้เล่นใหม่ แต่ก็สามารถลองทำได้</p><p>สำหรับคนที่ยังไม่รู้ว่า <strong>DeepSeek </strong>คืออะไรสามารถอ่านเพิ่มเติมได้ที่นี่</p><p><a href="https://medium.com/@spped2000/deepseek-%E0%B8%AA%E0%B8%B0%E0%B9%80%E0%B8%97%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B8%E0%B8%81%E0%B8%A7%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3-%E0%B8%97%E0%B8%B3%E0%B9%84%E0%B8%A1%E0%B8%84%E0%B8%B8%E0%B8%93%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-%E0%B8%A2%E0%B8%B4%E0%B9%88%E0%B8%87%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B8%A1%E0%B8%B1%E0%B8%99%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B8%A2%E0%B8%B4%E0%B9%88%E0%B8%87%E0%B8%94%E0%B8%B5-4580e297194a">DeepSeek: สะเทือนทุกวงการ ทำไมคุณต้องรู้จัก ยิ่งใช้งานมันเป็นยิ่งดี?</a></p><p>เห้ยแล้วทำไมผมใช้ <strong>SWARM? </strong>มันเป็นของ OpenAI ไม่ใช่เหรอ? นั่นแหละครับเหตุผล</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3rGTm0L86QHongPC0SCIKQ.jpeg" /><figcaption><a href="https://www.linkedin.com/posts/andreashorn1_aiops-aiagents-enterpriseai-activity-7290764681571373057--5NX/?utm_source=social_share_sheet&amp;utm_medium=android_app&amp;utm_campaign=copy_link">Source</a></figcaption></figure><p>โอเคทุกคนพร้อมเข้าไปในสู่โลกแห่ง Agents ที่ทุกๆแหล่งข่าวบอกปี 2025 คือยุคแห่ง Agents ยัง ผมก็เชื่ออย่างนั้นและในปีนี้ AI Agents น่าจะพัฒนาขึ้นไปอีกๆ</p><blockquote>OpenAI CEO Sam Altman said the first artificial intelligence agents might enter the workforce this year as his company inches closer to developing humanlike artificial general intelligence (<a href="https://cointelegraph.com/news/ai-took-giant-strides-2024-agi-comes-into-view">AGI</a>).</blockquote><blockquote>“We believe that, in 2025, we may see the first AI agents ‘join the workforce’ and materially change the output of companies,” <a href="https://blog.samaltman.com/reflections">said</a> Altman in a blog post titled “Reflections” on Jan. 6.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0Vk57YZmChlFGbs3.jpg" /><figcaption><a href="https://blog.samaltman.com/reflections">SAM ALTMAN CEO OpenAI เชื่อว่า AI Agents จะสร้างสร้างการเปลี่ยนแปลงอย่างมีนัยสำคัญต่อผลผลิตของบริษัทต่างๆ</a></figcaption></figure><blockquote>Nvidia CEO Jensen Huang is also <a href="https://cointelegraph.com/news/nvidia-touts-bright-future-agentic-ai-amid-record-q3-revenue">confident</a> that AI agents will become mainstream. “We’re starting to see enterprise adoption of agentic AI really is the latest rage,” he said at the firm’s earnings call in November.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4VuMGVweo5VrspXi" /><figcaption><a href="https://www.linkedin.com/pulse/nvidia-ceo-confirms-ai-die-book-agents-coming-2025-frank-shines-zakoe/">Nvidia CEO Jensen Huang มีความมั่นใจว่า AI เอเจนต์จะกลายเป็นกระแสหลัก โดยกล่าวว่า “เราเริ่มเห็นการนำ AI เอเจนต์มาใช้ในองค์กรซึ่งกำลังเป็นที่นิยมอย่างมาก</a></figcaption></figure><h3>ในบทความนี้ผมรันโมเดลผ่าน <strong>AWS EC2 (g4dn.xlarge) JupyterNotebook</strong> ผ่าน <strong>Docker</strong></h3><p>อันดับแรก วิธีการ setup ต่างๆ ถ้าผู้อ่านทำใน Local สามารถ setup ตามนี้ได้เลย</p><ol><li><a href="https://github.com/openai/swarm"><strong>SWARM</strong></a></li></ol><p><a href="https://github.com/openai/swarm">GitHub - openai/swarm: Educational framework exploring ergonomic, lightweight multi-agent orchestration. Managed by OpenAI Solution team.</a></p><p>2. <a href="https://github.com/ollama/ollama"><strong>Ollama</strong></a></p><p><a href="https://github.com/ollama/ollama">GitHub - ollama/ollama: Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.</a></p><p>3. <a href="https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct"><strong>Qwen2.5VL — 7B</strong></a></p><p><a href="https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct">Qwen/Qwen2.5-VL-7B-Instruct · Hugging Face</a></p><p>4. <a href="https://ollama.com/MFDoom/deepseek-r1-tool-calling"><strong>DeepSeek-R1–7B</strong></a></p><p><a href="https://ollama.com/MFDoom/deepseek-r1-tool-calling">MFDoom/deepseek-r1-tool-calling</a></p><h3>Let’s Cooking</h3><p>ไปตามหา api key ฟรีได้ที่ แค่สมัคร Login และก็เตรียมเป็นเชฟได้เลย!!</p><p><a href="https://huggingface.co/">Hugging Face — The AI community building the future.</a></p><pre>from huggingface_hub import login<br>login(token=&quot;your api key naja&quot;)</pre><p>ต่อไป ทำการโหลด Qwen2.5VL ซึ่งเป็น Multi-Modal สามารถรับข้อมูลที่เป็นรูปภาพได้จ้ะ</p><pre>from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor<br>from qwen_vl_utils import process_vision_info<br>import torch<br><br># default: Load the model on the available device(s)<br>model = Qwen2_5_VLForConditionalGeneration.from_pretrained(<br>    &quot;Qwen/Qwen2.5-VL-7B-Instruct&quot;, torch_dtype=&quot;auto&quot;, device_map=&quot;auto&quot;, load_in_4bit=True<br>)<br><br># We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.<br># model = Qwen2_5_VLForConditionalGeneration.from_pretrained(<br>#     &quot;Qwen/Qwen2.5-VL-7B-Instruct&quot;,<br>#     torch_dtype=torch.bfloat16,<br>#     attn_implementation=&quot;flash_attention_2&quot;,<br>#     device_map=&quot;auto&quot;,<br># )<br><br># default processer<br>processor = AutoProcessor.from_pretrained(&quot;Qwen/Qwen2.5-VL-7B-Instruct&quot;)<br><br></pre><p>แต่ถ้าออเจ้ามี GPU version ใหม่ตามนี้</p><p><strong>FlashAttention-2 with CUDA currently supports:</strong></p><ol><li>Ampere, Ada, or Hopper GPUs (e.g., A100, RTX 3090, RTX 4090, H100). Support for Turing GPUs (T4, RTX 2080) is coming soon, please use FlashAttention 1.x for Turing GPUs for now.</li><li>Datatype fp16 and bf16 (bf16 requires Ampere, Ada, or Hopper GPUs).</li><li>All head dimensions up to 256. Head dim &gt; 192 backward requires A100/A800 or H100/H800. Head dim 256 backward now works on consumer GPUs (if there’s no dropout) as of flash-attn 2.5.5.</li></ol><h3>สามารถใช้ flash attention2 ซึ่งดีกว่า</h3><pre> model = Qwen2_5_VLForConditionalGeneration.from_pretrained(<br>     &quot;Qwen/Qwen2.5-VL-7B-Instruct&quot;,<br>     torch_dtype=torch.bfloat16,<br>     attn_implementation=&quot;flash_attention_2&quot;,<br>     device_map=&quot;auto&quot;,<br> )</pre><p>ต่อไปเราก็เอารูปภาพที่ Bro ต้องการมาอัปโหลดได้เลย แล้วมาดูผลลัพธ์กัน</p><pre><br>from PIL import Image<br>import matplotlib.pyplot as plt<br>image_path = &quot;steak.jpg&quot;<br>image = Image.open(image_path)<br><br><br>messages = [<br>    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: [<br>        {&quot;type&quot;: &quot;image&quot;},<br>        {&quot;type&quot;: &quot;text&quot;, &quot;text&quot;: &quot;Describe this image. &quot;}<br>    ]}<br>]<br><br>input_text = processor.apply_chat_template(messages, add_generation_prompt=True)<br>inputs = processor(image, input_text, return_tensors=&quot;pt&quot;).to(model.device)<br>generated_ids = model.generate(**inputs, max_new_tokens=128)<br>generated_ids_trimmed = [<br>    out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)<br>]<br>output_text = processor.batch_decode(<br>    generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False<br>)<br>print(output_text)<br><br><br>plt.figure(figsize=(10, 8))<br><br><br>plt.imshow(image)<br><br><br><br>plt.axis(&#39;off&#39;)<br><br><br>plt.tight_layout()<br>plt.show()</pre><h3>Result Qwen2.5VL-7B</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-TJ3iybUEEULVumE6R0blg.png" /><figcaption>Steak.jpg</figcaption></figure><pre>[&#39;This image shows a plated meal consisting of a steak and French fries. The steak appears to be cooked to a medium-rare doneness, with a juicy interior and a nicely seared exterior.<br> It is sliced into portions and accompanied by a rich, dark sauce that pools around the meat. The French fries are golden brown and appear to be crispy on the outside. The plate is white is white white with black trim,<br> giving it a classic diner-style appearance. In the background, there is a fork resting on the edge of the plate, along with a glimpse of another dish containing salad greens.<br> A glass of red wine is also partially visible&#39;]</pre><h3>ต่อไป ผมจะสร้าง Agent ขึ้นโดยใช้ SWARM โดยดึงโมเดลจาก Ollama ซึ่งเป็นโมเดล DeepSeek-R1 7B</h3><pre>from openai import OpenAI<br><br>llm_client = OpenAI(<br>    base_url=&quot;http://localhost:11434/v1&quot;,<br>    api_key=&#39;ollama&#39;,  <br>)<br><br>model =&quot;MFDoom/deepseek-r1-tool-calling:7b&quot;</pre><h3>ผมสร้าง Agents 2 ตัว ตัวแรกเป็นเชฟมือดีจากแดนปลาดิบ ตัวที่สองเป็นผู้เชี่ยวชาญด้านสัตว์ป่า</h3><pre>from swarm import Swarm, Agent<br><br>client = Swarm(client=llm_client)<br><br>Animal_agent = Agent(<br>    name=&quot;Animal Agent&quot;,<br>    instructions=&quot;You are an expert in animal species and Zoos in Thailand&quot;,<br>    model=model,<br>)<br><br>food_agent = Agent(<br>    name=&quot;Food Agent&quot;,<br>    instructions=&quot;You are an expert in food and cooking.&quot;,<br>    model=model,<br>)<br><br># ถ้ามันมีการส่งไปให้อีก Agent นึงมันต้องปริ้นท์ &quot;## Transferring to Food agent.### &quot;<br>def transfer_to_agent():<br>    &quot;&quot;&quot;Transfer&quot;&quot;&quot;<br>    print(&quot;## Transferring to Food agent.### &quot;)<br>    return food_agent<br><br><br>Animal_agent.functions.append(transfer_to_agent)<br></pre><pre>messages = [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: f&quot;it&#39;s description from the {output_text} can you explaie me more?&quot;}]<br>response = client.run(agent=Animal_agent, messages=messages)<br>print(response.messages[-1][&quot;content&quot;])</pre><p>จากโค้ดข้างบนมันคือเวทมนต์นะ คือผมสั่ง AI เหมือนสั่งเพื่อนว่า เห้ยไอ้ Agent1 ที่เก่งเรื่องเกี่ยวกับสัตว์มากๆ ถ้าเจออะไรที่มันไม่เกี่ยวกับมึง ส่งไปให้ Agent2 ซึ่งเป็นเชฟแดนปลาดิบ และนี่คือผลลัพธ์…</p><pre>## Transferring to Food agent.### <br>&lt;/think&gt;<br>To understand this description of the plated meal, let&#39;s break down each element:<br><br>1. **Steak and Doneness:** The steak is medium-rare, which means it has a juicy interior that&#39;s still unlitigated with enough rareness (sought-after flavor) on the exterior due to searing.<br><br>2. **Sauce:** A rich, dark sauce surrounds the steak, contributing depth and flavor to the meal.<br><br>3. **French Fries:** Golden brown fries are crispy on the outside, indicating they&#39;ve been well-fried and cooked in batches for that char and texture.<br><br>4. **Plate Setup:** The white plate with black trim gives it a classic diner look—a clean background typical of many breakfast or casual dining settings.<br><br>5. **Dining Scene:** A fork partially resting on the edge shows someone is about to eat, likely indicating active eating. A salad greens dish suggests there are other items on the table besides just steak and fries.<br><br>6. **Beverage:** A glass of red wine visible in the background indicates someone&#39;s choice for a drink.<br><br>This description paints a picture of an enjoyable meal with a balance between the steak&#39;s flavor, the fries&#39; crispiness, and the overall dining atmosphere suggested by the plate setup and presence of other dishes or a drink.</pre><p>ผลลัพธ์เป็นที่น่าพอใจและมีการ transfer ไป Agent อีกตัวนึงเกิดขึ้น</p><h3>ต่อไปเราลองขยับมายากขึ้นอีกสั้กหน่อยดีมั้ย ?</h3><p>คราวนี้ผมลองเอาภาพหมูเด้งไปใส่ ในตัว Qwen ได้ผลลัพธ์ตามนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*msXOQEYjgoeTXPzKj94Erw.jpeg" /><figcaption>หมูเด้งงง</figcaption></figure><pre>[&#39;This image shows two baby hippos resting on the ground. The larger one appears to be an adult hippo,<br> possibly the mother, lying down with its head resting near the smaller baby hippo. Both animals have dark skin and appear to be wet, <br>suggesting they may have been in water recently. <br>The setting looks like a sandy area, likely part of their enclosure or habitat. The baby hippo has a pinkish hue around its mouth and nose,<br> which is typical for young hippos. The overall scene conveys a sense of calm and affection between the two hippos.&#39;]</pre><p>แต่ผมลองเปลี่ยนคำถาม?</p><pre>messages = [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: f&quot; {output_text} Where can I find it in Thailand?&quot;}]<br>response = client.run(agent=Animal_agent, messages=messages)<br>print(response.messages[-1][&quot;content&quot;])<br><br></pre><pre>&lt;think&gt;<br>First, analyze the query to understand the user&#39;s needs. The user provided an image description involving two baby hippos in Thailand and asked where it can be found.<br><br>I&#39;ll consider which tool would best address this type of question. Since the inquiry is about finding a specific animal in Thailand, I need a function that retrieves information about wildlife in the country.<br><br>Looking at the available tools, the most appropriate one here is the transfer_to_agent function because it allows using external knowledge sources to find specific information efficiently.<br><br>Since no parameters are required for this type of query, I&#39;ll set the parameters as empty within &quot;object&quot; properties.<br><br>Finally, structure the response into the expected JSON format with the chosen function and its parameters.<br>&lt;/think&gt;<br>```json<br>{&quot;name&quot;: &quot;transfer_to_agent&quot;, &quot;parameters&quot;:{&quot;type&quot;:&quot;object&quot;,&quot;required&quot;:[],&quot;properties&quot;:{&quot;function_name&quot;:&quot;Find_zoos_and_biodiversity_spots_in_Thailand&quot;,&quot;parameters&quot;:{&quot;image_description&quot;:&quot;The image contains two baby hippos, one larger identified as a mother possibly with a young baby, both in sandy habitat with pinkish features and calm interaction&quot;}}}<br>```</pre><p>จะเห็นได้ว่ามันตอบไม่ครบเพราะมันไม่รู้สถานที่ และไม่มีฟังก์ชันอื่นที่เชื่อมกับมันที่บอกสถานที่ได้</p><h3>ลองปรับกันสั้กหน่อย</h3><p>ผมได้เพิ่มฟังก์ชัน <strong>zoo_place </strong>เพื่อบอก <strong>Animal_agent </strong>ว่าเห้เพื่อนถ้านายไม่รู้ว่ามันคือสถานที่ไหนให้มาฟังก์ชันนี้ ซึ่งการใช้งานจริงสามารถเชื่อมกับ RAG หรือ API ภายนอกได้</p><pre>from swarm import Swarm, Agent<br><br><br>client = Swarm(client=llm_client)<br><br><br>Animal_agent = Agent(<br>    name=&quot;Animal Agent&quot;,<br>    instructions=(<br>        &quot;You are an expert in animal species and Zoos in Thailand. &quot;<br>        &quot;If you are not sure of the answer or if your output does not match the expected &quot;<br>        &quot;response, please trigger the zoo_place function to provide the default answer.&quot;<br>    ),<br>    model=model,<br>)<br><br><br>food_agent = Agent(<br>    name=&quot;Food Agent&quot;,<br>    instructions=&quot;You are an expert in food and cooking.&quot;,<br>    model=model,<br>)<br><br><br>def transfer_to_agent():<br>    &quot;&quot;&quot;Transfer control to the Food Agent.&quot;&quot;&quot;<br>    print(&quot;## Transferring to Food agent.### &quot;)<br>    return food_agent<br><br>.<br>def zoo_place(**kwargs):<br>    &quot;&quot;&quot;Return the default zoo location.&quot;&quot;&quot;<br>    print(&quot;Transferring to Zoo-Map Assistance&quot;)<br>    return &quot;KhaoKhew&quot;<br><br><br>Animal_agent.functions.extend([transfer_to_agent, zoo_place])<br><br><br>messages = [{<br>    &quot;role&quot;: &quot;user&quot;, <br>    &quot;content&quot;: f&quot;{output_text} Where can I find the famous place about it in Thailand?&quot;<br>}]<br><br><br>response = client.run(agent=Animal_agent, messages=messages)<br><br>.<br>print(response.messages[-1][&quot;content&quot;])</pre><p>แล้วมาดูผลลัพธ์สิ เห้ยยมันรู้แล้ว และมีการ transfer ไปฟังก์ชันจริงๆ</p><pre>Transferring to Zoo-Map Assistance<br>&lt;think&gt;<br>Okay, the user is asking about a famous place in Thailand related to a scene involving two baby hippos. The scene described includes an adult hippo serving as the mother and a smaller one acting as the baby, with dark skin suggesting recent water contact on sandy terrain.<br><br>First, I need to match this description with known locations in Thailand that have such animal exhibits. KhaoKhew National Park comes to mind because it&#39;s well-known for its hippopotamuses. I recall that there&#39;s an interpretative center where they showcase these animals in a natural habitat.<br><br>Considering the user is from Thailand and likely interested in zoos or nature reserves, mentioning KhaoKhew makes sense. It&#39;s an educational place where visitors can learn about wildlife, which aligns with their query about famous places related to the scene described.<br><br>I make sure to provide the full name of the park as it&#39;s a significant attraction. This should help the user find more information or plan their visit accordingly.<br>&lt;/think&gt;<br><br>The famous place you might be referring to in Thailand is **KhaoKhew National Park**</pre><h3>Bonus ภาษาไทย</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kii9H9S9YIhH-69_62GnwQ.png" /><figcaption>steak.jpg</figcaption></figure><pre>[&#39;ภาพนี้แสดงถ้วยอาหารที่มีเนื้อสัตว์และฟรายด์ฟรายส์บนจานขาวขอบดำ เนื้อสัตว์ถูกตัดเป็นชิ้นบางๆ<br> และมีเนื้อสัตว์ที่ยังไม่สุกอยู่ในช่วงกลาง <br>ฟรายด์ฟรายส์ด้านล่างของเนื้อสัตว์ดูเหมือนจะเป็นแบบทอดที่มีสีเหลืองอ่อน&#39;]</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df5d17be6d5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DeepSeek: สะเทือนทุกวงการ ทำไมคุณต้องรู้จัก ยิ่งใช้งานมันเป็นยิ่งดี?]]></title>
            <link>https://medium.com/@spped2000/deepseek-%E0%B8%AA%E0%B8%B0%E0%B9%80%E0%B8%97%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B8%97%E0%B8%B8%E0%B8%81%E0%B8%A7%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3-%E0%B8%97%E0%B8%B3%E0%B9%84%E0%B8%A1%E0%B8%84%E0%B8%B8%E0%B8%93%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-%E0%B8%A2%E0%B8%B4%E0%B9%88%E0%B8%87%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B8%A1%E0%B8%B1%E0%B8%99%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B8%A2%E0%B8%B4%E0%B9%88%E0%B8%87%E0%B8%94%E0%B8%B5-4580e297194a?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/4580e297194a</guid>
            <category><![CDATA[chinese]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[deepseek]]></category>
            <category><![CDATA[deepseek-r1]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 04:16:59 GMT</pubDate>
            <atom:updated>2025-01-29T04:16:59.051Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*31UQpvSaCiElphXr9Ru1Rw.jpeg" /><figcaption>สร้างภาพโดยใช้ DeepSeek <a href="https://huggingface.co/spaces/deepseek-ai/Janus-Pro-7B">Janus-Pro-7B</a></figcaption></figure><h3>บทความนี้เขียนในช่วง Chinese New Year ในปี 2025 จาก AI Engineer ที่ชื่นชอบใน Opensource</h3><p>ในเวลานี้ไม่มีใครไม่รู้จัก AI จากจีนที่ทรงพลังและสุดยอดสุดๆอย่าง <strong>DeepSeek</strong> ที่สะเทือนทุกวงการทั้งวงการ AI, หุ้น รวมถึงอนาคตของ LLMs ต่อจากนี้ และมุมมองของ <strong>Opensource</strong> ในปัจจุบันอาจจะถูกผลักดันมากขึ้นในทางที่ดี เพราะไม่ใช่แค่พี่ใหญ่จาก USA e.g. OpenAI, Gemini หรือ Claude ในบทความนี้จะพูดถึง <strong>DeepSeek</strong> แบบ<strong>ง่าย</strong>และ<strong>นุ่มลึก</strong>ไม่ได้ลงลึกถึง<strong>สถาปัตยกรรม </strong>หรือ <strong>คณิตศาสตร์เบื้องหลัง</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/0*1o4qw7KYg8S4-tfi" /><figcaption>โดนแล้ว!!!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*JMl45_tOnRHjjQ9G" /><figcaption>ทั้งใช้ทรัพยากรน้อยกว่าและถูกกว่าแถมยังเป็น Opensource!!!</figcaption></figure><p>เห้ยตอนนี้เราก็มี ChatGPT มี Gemini มี AI มากมายรอบตัวรวมถึงของ Meta หรือ llama แล้วทำไม <strong>DeepSeek</strong> ถึงสำคัญและสำคัญมากๆ</p><p>ก่อนอื่นผมขอยก benchmark มาเปรียบเทียบระหว่าง OpenAI-o1 (ChatGPT) และ DeepSeek-R1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*owCE8vUalz4BhW8o.png" /><figcaption><a href="https://x.com/deepseek_ai/status/1881318130334814301">source</a></figcaption></figure><p>R1 และ o1 เป็นโมเดลที่แทบจะเหมือนกันเมื่อวัดจากการประเมิน โดยความแตกต่างที่ใหญ่ที่สุดคือ GPQA Diamond (71.5% เทียบกับ 75.7%)</p><p>เพื่อทำความเข้าใจเพิ่มเติม นี่คือผลลัพธ์ของ o1 กับ GPT-4o (โมเดลที่ดีที่สุดที่ไม่ได้ใช้ Reasoning ของ OpenAI) บนสาม benchmarks ดังกล่าว (Anthropic’s Claude 3.5 และ Google DeepMind’s Gemini 2.0 อยู่ในระดับใกล้เคียงกับ GPT-4o):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ISYWuY2chBlXy9yU.png" /><figcaption><a href="https://openai.com/index/learning-to-reason-with-llms/">source</a></figcaption></figure><p>เราจะเห็นช่องว่าง 85% ระหว่าง R1 และ GPT-4o บน <strong>Codeforces</strong> (การเขียนโค้ด), ช่องว่าง 75% บน <strong>AIME</strong> (คณิตศาสตร์), และช่องว่าง 15% บน <strong>GPQA Diamond</strong> (วิทยาศาสตร์) สรุปได้ว่า DeepSeek ได้สร้างโมเดลที่เทียบเคียงได้กับโมเดลที่ดีที่สุดของ OpenAI ซึ่งก็เป็นโมเดลที่ดีที่สุดในบรรดาห้องปฏิบัติการของสหรัฐอเมริกา (แต่ว่า OpenAI ได้ประกาศ <strong>o3</strong> แล้ว ซึ่งดีกว่า <strong>o1</strong> มาก แต่ยังไม่ได้เริ่มปล่อย คาดว่าจะออกมาในอีกไม่กี่เดือนข้างหน้า) DeepSeek อยู่ในตำแหน่งบน podium และด้วยการ open-source R1 มันคือสิ่งที่สุดยอดทำแบบไม่หวังผลตอบแทนยังไงล่ะ!!!</p><p><strong>R1</strong>, <strong>R1-Zero</strong> แล้ว <strong>R</strong> ใน DeepSeek-R1 มันคืออะไร มันคือ <strong>Reasoning</strong> หรือ <strong>เหตุผล</strong>นั้นเอง โดยใช้กระบวนการที่เรียกว่า <strong>reinforcement learning (RL) </strong>และทำให้มันแตกต่าง<strong> (</strong><a href="https://medium.com/@isaakmwangi2018/a-simple-guide-to-deepseek-r1-architecture-training-local-deployment-and-hardware-requirements-300c87991126">Unlike traditional models that predominantly rely on supervised learning, DeepSeek-R1 uses RL extensively.</a>)</p><p>สำหรับคนที่ไม่ได้อยู่ในวงการเทคโนโลยี ผมจะอธิบาย <strong>reinforcement learning (RL) </strong>คร่าวๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*31ff1fuXpMH3MkSN.jpg" /><figcaption><a href="https://databasetown.com/basics-of-reinforcement-learning/">ตัวอย่าง <strong>reinforcement learning (RL)</strong></a></figcaption></figure><ul><li><strong>Agent (ตัวแทนการเรียนรู้):</strong> ในที่นี้คือ <strong>เด็ก</strong> ที่พยายามเรียนรู้ทักษะการคลาน</li><li><strong>Environment (สิ่งแวดล้อม):</strong> พื้นที่รอบตัวเด็กที่ต้องมีปฏิสัมพันธ์ เช่น พื้นห้อง อุปกรณ์ขวางทาง</li><li><strong>Action (การกระทำ):</strong> การเคลื่อนไหวของเด็ก เช่น ดันแขน ยกเข่า ถอยหลัง</li><li><strong>Reward (รางวัล):</strong> นมหรือจุกนมที่ได้รับเมื่อทำสำเร็จ <em>(“คลานมาถึงจุดหมาย → ได้รางวัล”)</em></li></ul><h3>กลไกการเรียนรู้ผ่าน Trial and Error</h3><p>เด็กจะเริ่มด้วยการลองเคลื่อนไหวแบบสุ่ม (<strong>Exploration</strong>) เช่น คว้าสิ่งของใกล้ตัว หรือล้มไปด้านข้าง เมื่อใดที่การกระทำนั้นทำให้เข้าใกล้รางวัล (เช่น คลานไปข้างหน้าได้ครึ่งเมตร) ระบบจะให้ <strong>Positive Reward</strong> เพื่อสร้างแรงจูงใจ ในทางตรงข้าม หากเด็กเคลื่อนไหวแล้วห่างจากเป้าหมาย (เช่น ถอยหลัง) อาจได้ <strong>Negative Reward</strong> (หรือไม่ได้รับรางวัล) ทำให้เรียนรู้ว่าควรหลีกเลี่ยงการกระทำนั้น</p><h3>การสร้าง Policy (นโยบายการตัดสินใจ)</h3><p>เมื่อเด็กทดลองซ้ำๆ ร่างกายและสมองจะปรับปรุง <strong>Policy</strong> ที่เชื่อมโยง <strong>State</strong> (สถานะปัจจุบัน เช่น ตำแหน่งของเด็ก) กับ <strong>Action</strong> ที่ให้รางวัลสูงสุด เช่น “ถ้ายกเข่าขวาในขณะที่มือซ้ายยันพื้น → โอกาสได้นมเพิ่มขึ้น 80%” นี่คือกระบวนการที่ DeepSeek-R1 ใช้เพื่อหา <strong>Optimal Policy</strong> ผ่านอัลกอริธึมเช่น Q-Learning หรือ Deep Q-Network (DQN)</p><h3>ความคล้ายคลึงกับ DeepSeek-R1</h3><ul><li><strong>Exploration vs. Exploitation:</strong> เด็กต้องสมดุลระหว่าง “ลองเคลื่อนไหวใหม่ๆ” (เพื่อค้นหาวิธีที่ดีกว่า) กับ “ทำตามวิธีที่เคยได้รางวัล” เช่นเดียวกับที่ DeepSeek-R1 ใช้เทคนิคอย่าง <strong>ε-Greedy</strong> เพื่อไม่ให้ติดกับดักวิธีเดิม</li><li><strong>Delayed Reward:</strong> เด็กอาจไม่ได้รับนมทันทีที่เริ่มคลาน แต่ต้องรอจนถึงจุดหมาย เช่นเดียวกับงาน RL ที่รางวัลอาจมาช้า (เช่น การเล่นเกมที่ต้องผ่านหลายด่าน)</li></ul><h3><strong>Distillation Techniques</strong></h3><p>คือเทคนิคการ “กลั่นความรู้” จาก <strong>โมเดลใหญ่ (Teacher Model)</strong> ที่มีความซับซ้อน ไปสู่ <strong>โมเดลเล็ก (Student Model)</strong> ที่ใช้งานง่ายกว่า แต่ยังคงประสิทธิภาพใกล้เคียงกัน คล้ายกับ <strong>ครูสอนนักเรียน</strong> ให้ทำตามแบบอย่าง แต่ใช้ AI เป็นตัวกลาง</p><h3>ทำไมต้องใช้ Distillation?</h3><ul><li><strong>โมเดลใหญ่ (เช่น GPT-4)</strong> มีความสามารถสูง แต่กินทรัพยากรมาก ใช้เวลาและพลังงานสูง</li><li><strong>โมเดลเล็ก (Student)</strong> หลังผ่านการกลั่นความรู้ จะทำงานเร็วขึ้น กินทรัพยากรน้อยลง แต่ยังทำหน้าที่ได้ดี<br>→ เหมือน <strong>ย่อตำราขนาด 1,000 หน้า ให้เหลือ 100 หน้า โดยเก็บเนื้อหาสำคัญไว้</strong></li></ul><p>มันเลยทำให้โมเดล <strong>DeepSeek</strong> มี<strong>ขนาดเล็ก</strong>แต่ยังให้<strong>ผลลัพธ์ที่ดีมาก แถมยังถูก</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LIcCPeKtS16xDCbz" /><figcaption><a href="https://www.threads.net/@m_zafarr/post/DFE0LB_tN1B">เปรียบเทียบราคา — source</a></figcaption></figure><h3>ทำไมมันถูกจัง Bro?</h3><ul><li><strong>MoE</strong></li><li><strong>MLA</strong></li><li><strong>FP8</strong></li><li><strong>MTP</strong></li><li><strong>Caching</strong></li><li><strong>Cheap electricity</strong></li><li><strong>Cheaper costs in China in general</strong></li></ul><p>ก็คือมีทั้ง Architecture ข้างในมันทำให้ถูกและยังมีเหตุผลทางด้านการเมือง และก็ OpenAI ตั้งแพงรึเปล่า(ตัวO1)? (ฝากไว้ให้คิด)</p><h3>สุดท้ายนี้บทความนี้เป็นการชี้แจงและอธิบายตัว DeepSeek ตามความเข้าใจของผู้เขียน ซึ่ง DeepSeek มันเก่งแต่ก็ยังคิดว่าสู้โมเดลใหญ่ๆอย่าง O1 ไม่ได้ แต่ถ้าด้านความคุ้มค่ากินขาดแน่นอน</h3><h3>และใครชอบใช้ AI ตัวไหนลองใช้ตามความคล่องมือได้เลย DeepSeek ก็คืออีก Model นึงที่เอามาลองใช้ประยุกต์ได้ แต่ที่แน่ๆมันคือ Opensource</h3><p>Ref.</p><ul><li><a href="https://albertoromgar.medium.com/deepseek-is-chinese-but-its-ai-models-are-from-another-planet-e4cf94840086">DeepSeek Is Chinese But Its AI Models Are From Another Planet</a></li><li><a href="https://www.longtunman.com/56521">DeepSeek สะเทือนทั้งตลาด Nasdaq Futures -5% ส่วน Nvidia -12%..</a></li><li><a href="https://doi.org/10.48550/arXiv.2410.13848">Janus: Decoupling Visual Encoding for Unified Multimodal Understanding and Generation</a></li><li><a href="https://doi.org/10.48550/arXiv.2402.03300">DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models</a></li><li><a href="https://medium.com/@namnguyenthe/deepseek-r1-architecture-and-training-explain-83319903a684">DeepSeek-R1: Architecture and training explain</a></li><li><a href="https://doi.org/10.48550/arXiv.2501.12948">DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning</a></li><li><a href="https://www.longtunman.com/56533">Sam Altman ซีอีโอ OpenAI บอกว่า เขาประทับใจในโมเดลของ DeepSeek โดยเฉพาะในเรื่องของต้นทุน</a></li><li><a href="https://medium.com/@isaakmwangi2018/a-simple-guide-to-deepseek-r1-architecture-training-local-deployment-and-hardware-requirements-300c87991126">A Simple Guide to DeepSeek R1: Architecture, Training, Local Deployment, and Hardware Requirements</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4580e297194a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Manual to Magic: Automated Labeling with SAM2, Florence2, and Gradio]]></title>
            <link>https://medium.com/@spped2000/from-manual-to-magic-automated-labeling-with-sam2-florence2-and-gradio-7eda500a8ef1?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eda500a8ef1</guid>
            <category><![CDATA[labels]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[gradio]]></category>
            <category><![CDATA[florence-2]]></category>
            <category><![CDATA[sam2]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Thu, 26 Sep 2024 10:34:19 GMT</pubDate>
            <atom:updated>2024-09-26T10:34:19.710Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there! Ever felt like labeling images for your AI projects is a real pain? Well, you’re not alone. It’s been a major headache for folks in computer vision and machine learning for ages. But guess what? We’ve got some cool new AI tricks up our sleeves that are about to change the game.</p><p>Let me introduce you to our magical trio: SAM2, Florence2, and Gradio. SAM2 is like the cool new kid on the block — it’s the next generation of Meta AI’s Segment Anything Model, and it’s seriously good at figuring out what’s what in an image. Then we’ve got Florence2, another AI brainiac that’s amazing at understanding what it’s looking at. Put these two together, and you’ve got a powerhouse team for automated image labeling.</p><p>But wait, there’s more! We’ve wrapped all this AI goodness in a user-friendly package called Gradio. It’s like the friendly face of our project, making sure that whether you’re a seasoned pro or just starting out, you can easily use these powerful tools.</p><p>Now, I’ve got to give a shoutout to the awesome folks at IDEA Research. Their Grounded-SAM-2 project on GitHub(<a href="https://github.com/IDEA-Research/Grounded-SAM-2.git">https://github.com/IDEA-Research/Grounded-SAM-2.git</a>) really got our gears turning. We took their brilliant idea and ran with it, adding Florence2 to the mix to create something even cooler.</p><p>So, ready to see how we’re turning the chore of image labeling into a piece of cake? Let’s dive in!</p><p><a href="https://github.com/spped2000/Florence2SAM2_Labelanything.git">GitHub - spped2000/Florence2SAM2_Labelanything: Florence2 + SAM2 label by prompt</a></p><p>With the Florence2SAM2_Labelanything that I’ve created, you can label anything in the world, multiple images at once, using just a prompt as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jtN_U-dB97NGM3WeJ3swjQ.png" /><figcaption>example1 input prompt “human face”</figcaption></figure><p>After the process is complete, you can choose to save the results as either masks or boxes, depending on your task — whether you’re doing object detection or segmentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*dR_YPp7WqHS0wXrz2xGARg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*QZQ3-BNM_j9Ac6u9OwaKRg.png" /><figcaption>label and original images (YOLOV8 format)</figcaption></figure><h3>References</h3><ol><li>Ravi, N., Gabeur, V., Hu, Y.-T., Hu, R., Ryali, C., Ma, T., Khedr, H., Rädle, R., Rolland, C., Gustafson, L., Mintun, E., Pan, J., Alwala, K.V., Carion, N., Wu, C.-Y., Girshick, R., Dollár, P. and Feichtenhofer, C. (2024). SAM 2: Segment Anything in Images and Videos. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2408.00714">https://arxiv.org/abs/2408.00714</a> [Accessed 26 Sep. 2024].</li><li>Xiao, B., Wu, H., Xu, W., Dai, X., Hu, H., Lu, Y., Zeng, M., Liu, C. and Yuan, L. (2023). Florence-2: Advancing a Unified Representation for a Variety of Vision Tasks. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2311.06242">https://arxiv.org/abs/2311.06242</a> [Accessed 26 Sep. 2024].</li><li>Ravi, N., Gabeur, V., Hu, Y.-T., Hu, R., Ryali, C., Ma, T., Khedr, H., Rädle, R., Rolland, C., Gustafson, L., Mintun, E., Pan, J., Alwala, K.V., Carion, N., Wu, C.-Y., Girshick, R., Dollár, P. and Feichtenhofer, C. (2024). SAM 2: Segment Anything in Images and Videos. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2408.00714">https://arxiv.org/abs/2408.00714</a> [Accessed 26 Sep. 2024].</li><li>Liu, S., Zeng, Z., Ren, T., Li, F., Zhang, H., Yang, J., Li, C., Yang, J., Su, H., Zhu, J. and others (2023). Grounding dino: Marrying dino with grounded pre-training for open-set object detection. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2303.05499">https://arxiv.org/abs/2303.05499</a> [Accessed 26 Sep. 2024].</li><li>Ren, T., Jiang, Q., Liu, S., Zeng, Z., Liu, W., Gao, H., Huang, H., Ma, Z., Jiang, X., Chen, Y., Xiong, Y., Zhang, H., Li, F., Tang, P., Yu, K. and Zhang, L. (2024). Grounding DINO 1.5: Advance the “Edge” of Open-Set Object Detection. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2405.10300">https://arxiv.org/abs/2405.10300</a> [Accessed 26 Sep. 2024].</li><li>Ren, T., Liu, S., Zeng, A., Lin, J., Li, K., Cao, H., Chen, J., Huang, X., Chen, Y., Yan, F., Zeng, Z., Zhang, H., Li, F., Yang, J., Li, H., Jiang, Q. and Zhang, L. (2024). Grounded SAM: Assembling Open-World Models for Diverse Visual Tasks. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2401.14159">https://arxiv.org/abs/2401.14159</a> [Accessed 26 Sep. 2024].</li><li>Kirillov, A., Mintun, E., Ravi, N., Mao, H., Rolland, C., Gustafson, L., Xiao, T., Whitehead, S., Berg, A.C., Lo, W.-Y., Dollár, P. and Girshick, R. (2023). Segment Anything. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2304.02643">https://arxiv.org/abs/2304.02643</a> [Accessed 26 Sep. 2024].</li><li>Jiang, Q., Li, F., Zeng, Z., Ren, T., Liu, S. and Zhang, L. (2024). T-Rex2: Towards Generic Object Detection via Text-Visual Prompt Synergy. [online] arXiv.org. Available at: <a href="https://arxiv.org/abs/2403.14610">https://arxiv.org/abs/2403.14610</a> [Accessed 26 Sep. 2024].</li><li><a href="https://www.gradio.app/">Gradio</a></li><li><a href="https://github.com/IDEA-Research/Grounded-SAM-2?tab=readme-ov-file#grounded-sam-2-florence-2-image-auto-labeling-demo">IDEA-Research/Grounded-SAM-2: Grounded SAM 2: Ground and Track Anything in Videos with Grounding DINO, Florence-2 and SAM 2 (github.com)</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eda500a8ef1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effortless Parallel Custom Deep Learning Model with Ray: A Practical Guide]]></title>
            <link>https://medium.com/@spped2000/effortless-parallel-custom-deep-learning-model-with-ray-a-practical-guide-0e77b1f399e2?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e77b1f399e2</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Fri, 30 Aug 2024 09:29:08 GMT</pubDate>
            <atom:updated>2024-08-30T17:30:20.968Z</atom:updated>
            <content:encoded><![CDATA[<p>I mainly focus on <strong>GPU </strong>parallelism.</p><p>Today, I’ll discuss how to use the Ray framework to scale a custom AI model across a single <strong>GPU</strong>, enabling parallel processing to handle multiple tasks simultaneously and reduce latency in both practical applications and production environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4-mSgcQz_FUS5yXcHJSQQ.png" /><figcaption><a href="https://docs.ray.io/en/latest/ray-overview/index.html">Overview — Ray 2.34.0</a></figcaption></figure><p>Now I focus on the <strong>Ray Core</strong> for low-level design</p><p><strong>Ray Core</strong>–An open-source, Python, general purpose, distributed computing library that enables ML engineers and Python developers to scale Python applications and accelerate machine learning workloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lV-SDsIFFj4N7snt.png" /><figcaption><a href="https://docs.ray.io/en/latest/ray-overview/index.html">Overview — Ray 2.34.0</a></figcaption></figure><p><strong>Ray</strong> is a tool that helps you run Python and AI applications faster by splitting the work across multiple computers. You don’t need to be an expert in complex systems to use it. Ray makes it easier to run big machine learning tasks like training models, tuning settings, and making decisions quickly.</p><p><strong>Key Points:</strong></p><ul><li><strong>Libraries:</strong> Ray has built-in tools for common machine learning tasks, making them run faster and more efficiently.</li><li><strong>Easy to Use:</strong> You can easily spread your Python tasks across multiple computers, even if you’re not familiar with how to manage many computers at once.</li><li><strong>Integration:</strong> Ray works well with other popular tools and cloud platforms like AWS, Google Cloud, and Azure.</li><li><strong>For Data Scientists and ML Engineers:</strong> Ray helps you scale your work from a single computer to a whole cluster without much hassle. This means you can work with bigger data and more complex models easily.</li><li><strong>For System Engineers:</strong> Ray automatically handles complex tasks like managing resources, deciding where and when tasks run, and adjusting to changing needs, so you don’t have to worry about these details.</li></ul><p>Let’s <strong>experiment</strong>!</p><p>My initial experiment involves simulating the sequential processing of videos without using Ray to measure the time each video takes to process. This will allow for a comparison between normal sequential processing and parallel processing with Ray.</p><pre>input_folder = &quot;&quot;<br>output_folder = &quot;&quot;<br>result_file = &quot;&quot;<br><br><br>input_videos = glob.glob(os.path.join(input_folder, &quot;*.mp4&quot;))<br><br><br>print(&quot;Input videos:&quot;)<br>for video in input_videos:<br>    print(video)<br><br>results = []<br><br>for input_video in input_videos:<br>    output_video = os.path.join(output_folder, os.path.basename(input_video))<br>    <br>    bash_command = [<br>       # your model<br>    ]<br>    <br>    result = subprocess.run(bash_command, capture_output=True, text=True)<br>    if result.returncode == 0:<br>        print(f&quot;Successfully ran the bash script for {input_video}. Output video: {output_video}&quot;)<br>        result_stdout = result.stdout.strip().splitlines()<br>        action_label = None<br>        confidence = None<br>        for line in result_stdout:<br>            if &quot;Class: boxing&quot; in line:<br>                fraud_confidence = float(line.split()[-1])<br>            elif &quot;Class: karate&quot; in line:<br>                normal_confidence = float(line.split()[-1])<br>            elif line.lower() in [&quot;boxing&quot;, &quot;karate&quot;]:<br>                action_label = line.capitalize()<br>                if action_label == &quot;Boxing&quot;:<br>                    confidence = fraud_confidence<br>                elif action_label == &quot;Karate&quot;:<br>                    confidence = normal_confidence<br>                break  <br>        if action_label and confidence is not None:<br>            current_time = datetime.now().strftime(&#39;%d/%m/%Y %H:%M:%S&#39;)<br>            print(f&quot;{input_video} -&gt; {action_label} ({confidence:.2f}) at {current_time}&quot;)<br>            results.append(f&quot;{input_video} -&gt; {action_label} Confidence: {confidence:.2f} at {current_time}&quot;)<br>    else:<br>        print(f&quot;Failed to process {input_video}. Error: {result.stderr}&quot;)<br><br># Write results to the text file<br>with open(result_file, &quot;w&quot;) as file:<br>    for result in results:<br>        file.write(result + &quot;\n&quot;)<br><br>print(f&quot;Results have been written to {result_file}&quot;)</pre><p>Let’s see the result!</p><p><strong>sequential</strong> 4 clips: 2 minutes and 21 seconds.</p><pre>Karate2.mp4 -&gt; Karate Confidence: 1.00 at 30/08/2024 16:03:15<br>Boxing2.mp4 -&gt; Boxing Confidence: 0.95 at 30/08/2024 16:04:17<br>Karate1.mp4 -&gt; Karate Confidence: 1.00 at 30/08/2024 16:04:54<br>Boxing1.mp4 -&gt; Boxing Confidence: 0.68 at 30/08/2024 16:05:36</pre><p>Experiment 2 Use <strong>Ray</strong> for <strong>Parallel processing</strong></p><p>First Initialize Ray with 1 GPU, allowing 4 parallel tasks each using 0.25 GPU</p><pre>ray.init(num_cpus=4, num_gpus=1, include_dashboard=True)</pre><p>Set the number of tasks you want to fractionally allocate for parallel processing so that multiple tasks and actors can share the same accelerator. Currently, I set num_gpus=0.25 to run 4 tasks in parallel.</p><pre>@ray.remote(num_gpus=0.25)</pre><pre>import ray<br><br><br># Initialize Ray with 1 GPU, allowing 4 parallel tasks each using 0.25 GPU<br>ray.init(num_cpus=4, num_gpus=1, include_dashboard=True)<br><br>input_folder = &quot;&quot;<br>output_folder = &quot;&quot;<br>result_file = &quot;&quot;<br><br><br>input_videos = glob.(os.path.join(input_folder, &quot;*.mp4&quot;))<br><br><br>print(&quot;Input videos:&quot;)<br>for video in input_videos:<br>    print(video)<br><br>@ray.remote(num_gpus=0.25) ### <br>def process_video(input_video):<br>    output_video = os.path.join(output_folder, os.path.basename(input_video))<br>    <br>    bash_command = [<br>           # your model<br>        ]<br>    <br>    result = subprocess.run(bash_command, capture_output=True, text=True)<br>    <br>    if result.returncode == 0:<br>        completion_time = datetime.now().strftime(&quot;%d/%m/%Y %H:%M:%S&quot;)<br>        print(f&quot;Successfully ran the bash script for {input_video}. Output video: {output_video} at {completion_time}&quot;)<br>        result_stdout = result.stdout.strip().splitlines()<br>        action_label = None<br>        confidence = None<br>        for line in result_stdout:<br>            if &quot;Class: boxing&quot; in line:<br>                fraud_confidence = float(line.split()[-1])<br>            elif &quot;Class: karate&quot; in line:<br>                normal_confidence = float(line.split()[-1])<br>            elif line.lower() in [&quot;boxing&quot;, &quot;karate&quot;]:<br>                action_label = line.capitalize()<br>                if action_label == &quot;Boxing&quot;:<br>                    confidence = fraud_confidence<br>                elif action_label == &quot;Karate&quot;:<br>                    confidence = normal_confidence<br>                break  <br>        if action_label and confidence is not None:<br>            result_str = f&quot;{input_video} -&gt; {action_label} Confidence: {confidence:.2f} | Success at {completion_time}&quot;<br>            print(result_str)<br>            return result_str<br>    else:<br>        error_msg = f&quot;Failed to process {input_video}. Error: {result.stderr}&quot;<br>        print(error_msg)<br>        return error_msg<br><br><br>result_futures = [process_video.remote(video) for video in input_videos]<br>results = ray.get(result_futures)<br><br><br>with open(result_file, &quot;w&quot;) as file:<br>    for result in results:<br>        file.write(result + &quot;\n&quot;)<br><br>print(f&quot;Results have been written to {result_file}&quot;)<br><br><br>ray.shutdown()</pre><p>Let’s see the experiment2 result!</p><p><strong>parallel</strong> 4 clips: 32 seconds.</p><pre>Karate2.mp4 -&gt; Karate Confidence: 1.00 | Success at 30/08/2024 16:09:06<br>Boxing2.mp4 -&gt; Boxing Confidence: 0.95 | Success at 30/08/2024 16:09:27<br>Karate1.mp4 -&gt; Karate Confidence: 1.00 | Success at 30/08/2024 16:08:55<br>Boxing1.mp4 -&gt; Boxing Confidence: 0.68 | Success at 30/08/2024 16:09:03</pre><h3>Ray Dashboard</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LDg3_ro02EwrUcR6" /><figcaption>Ray Dashboard for parallel 4 process</figcaption></figure><h3><strong>Ray Monitor</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6RCAOq4DmwUZKUra" /></figure><h3>Conclusion</h3><p>The parallel method completed the task approximately <strong>4.4 times faster</strong> than the sequential method.</p><h3>References</h3><p>(1) <a href="https://docs.ray.io/en/latest/ray-core/scheduling/accelerators.html">Accelerator Support — Ray 2.34.0</a></p><p>(2) <a href="https://docs.ray.io/en/latest/ray-overview/index.html">Overview — Ray 2.34.0</a></p><p>(3) <a href="https://github.com/ray-project/ray">ray-project/ray: Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads. (github.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e77b1f399e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[สรุปงาน Code the Future: ประสบการณ์การสร้างแอปกับ AWS PartyRock จากมุมมองของผู้ชนะรางวัล]]></title>
            <link>https://medium.com/@spped2000/%E0%B8%AA%E0%B8%A3%E0%B8%B8%E0%B8%9B%E0%B8%87%E0%B8%B2%E0%B8%99-code-the-future-%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%AA%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%93%E0%B9%8C%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B9%81%E0%B8%AD%E0%B8%9B%E0%B8%81%E0%B8%B1%E0%B8%9A-aws-partyrock-%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%A1%E0%B8%B8%E0%B8%A1%E0%B8%A1%E0%B8%AD%E0%B8%87%E0%B8%82%E0%B8%AD%E0%B8%87%E0%B8%9C%E0%B8%B9%E0%B9%89%E0%B8%8A%E0%B8%99%E0%B8%B0%E0%B8%A3%E0%B8%B2%E0%B8%87%E0%B8%A7%E0%B8%B1%E0%B8%A5-f410567672e9?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/f410567672e9</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[awscodethefuture]]></category>
            <category><![CDATA[awsgenai]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws-partyrock]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Sat, 03 Aug 2024 16:34:07 GMT</pubDate>
            <atom:updated>2024-08-03T16:34:07.900Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ ผม <strong>จ๊อบ</strong> เป็นผู้เข้าร่วมงาน <strong>Code The Future</strong> ที่จัดในวันที่ 3 สิงหาคม 2024 ที่ผ่านมาโดยเป็นการร่วมของ <a href="https://www.facebook.com/groups/awsusergroup/"><strong>AWS User Group (Thailand)</strong></a><strong> กับ AWS ประเทศไทย </strong>ซึ่งเป็นงานที่สนุกมากๆ และเป็นครั้งที่ 2 ที่ผมได้มาร่วมงานที่ ออฟฟิศของ AWS ซึ่งได้ความรู้และสนุกทุกงาน (ซึ่งทุกอย่างในงานฟรีนะครับตั้งแต่ลงทะเบียนจนถึงการทำ Workshop ที่สำคัญกาแฟ AWS อร่อย)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CSdtKvUOdZZ00cSH" /><figcaption>ขอบคุณรูปภาพจากกลุ่ม AWS User Group (Thailand)</figcaption></figure><figure><img alt="ขอบคุณรูปภาพจากกลุ่ม AWS User Group(Thailand)" src="https://cdn-images-1.medium.com/max/720/0*hOCWf1UX9EjBWudg" /><figcaption>ขอบคุณรูปภาพจากกลุ่ม AWS User Group (Thailand)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ntNZlo9cXnBdev4V" /><figcaption>ตัวผมเอง (JOB)</figcaption></figure><p>ก่อนหน้านี้ AWS Thailand ได้จัด Challenges ตัวนึงที่น่าสนใจและน่าดึงดูดมาก ชื่อ <strong>PartyRock App Challenge </strong>แม้ว่ากิจกกรรมจะสิ้นสุดแล้วแต่เพื่อนๆ สามารถเข้าไปเล่นได้ตลอด — → <a href="https://partyrock.aws/">partyrock.aws</a></p><p>โดยตัว Application ที่ผมสร้างแล้วได้รับรางวัลมีรายละเอียดตามด้านล่างครับ</p><p><strong>App — AI engineer Roadmap</strong></p><p>ทำแอปง่ายๆโดยไม่ต้องเขียนโค้ดใช้เวลาไม่ถึง <strong>3 นาที</strong></p><p>ส่วนตัวเป็น <strong>AI Engineer </strong>แล้วมีคนรู้จักและรุ่นน้องนักศึกษาหลายคนที่สนใจด้านนี้ และก็ให้คำปรึกษาไปพอสมควร แต่จะดีกว่ามั้ยถ้ามี AI อัจฉริยะ มาช่วยให้คำปรึกษาที่ตรงกว่ามีข้อมูลมากกว่าและตรงจุดมากกว่า โดยอิงจาก — ประสบการณ์ของแต่ละคนว่าเรียนอะไรมาบ้าง</p><p><strong>- ถนัดอะไรมา</strong></p><p><strong>- งานอดิเรก</strong></p><p><strong>- ถนัดโปรแกรมมิ่ง ภาษาอะไร</strong></p><p>และเสริมจาก journey การที่เราจะเป็น AI engineer นอกจากอ่านหนังสือ เรียนจาก youtube ลองทำโปรเจค สิ่งที่สำคัญมากๆเช่นกันก็คืองาน event ที่จะมี speaker ที่มีประสบการณ์ตามสายงานด้านนั้นๆ มาพูด และสรุปให้เป็นเรื่องที่เข้าใจง่าย แถมยังมีโอกาสได้สอบถามตรงๆกับผู้เชี่ยวชาญในเรื่องที่เราติดปัญหา โดยผมจะกำหนด field เพิ่มมาอีก 2 field ก็คือ</p><p><strong>- Area Location ( ประเทศที่อยู่)</strong></p><p><strong>- Field of Interest (สนใจด้านไหนของ AI อยู่)</strong></p><p>เพื่อให้ AI generate event ที่เหมาะสมกับเรามากที่สุดพร้อมอธิบายแต่ละ event เพื่อประกอบการตัดสินใจ</p><p>ส่วนสุดท้ายจะเป็นส่วนให้ลองเล่นจริงๆ โดย user สามารถ input dataset ที่เป็น csv อย่างเช่นตัวอย่างใช้ Iris dataset</p><p>โดย user สามารถใช้</p><p><strong>- Explore dataset</strong></p><p>เพื่อศึกษาดูรายละเอียดของ dataset ได้คร่าวๆ เช่น มีทั้งหมดกี่คลาส เป็น dataset เกี่ยวกับอะไร มีกี่คอลัมน์ etc.</p><p><strong>- ML techniques</strong></p><p>เป็นสิ่งที่ user สามมารถ input task ต่างๆ ให้ AI ลองทำกับตัว Dataset e.g. Data Cleaning, Clustering, Classification แล้วให้ตัว AI generate pipeline step by step โดยจะมีทั้ง Description และตัวอย่าง Code ให้ user สามารถเอาไปรันในเครื่องตัวเอง และศึกษาเพิ่มเติมได้</p><p>สามารถไปลองเล่นได้ที่</p><p><a href="https://partyrock.aws/u/spped2000/wH5mC9n18/AI-Engineering-Roadmap?fbclid=IwZXh0bgNhZW0CMTAAAR0MXj3MFnXRi9-i5nXaAqC9pg_hqoeXl7rAcp4WkCUldo4UJXIB2vcxsfY_aem_BZI8_4UMU2P-GzMjPtSUEQ">https://partyrock.aws/.../wH5mC9n18/AI-Engineering-Roadmap</a></p><p>สามารถลองสร้างแอปของตัวเองได้ที่</p><p><a href="https://l.facebook.com/l.php?u=https%3A%2F%2Fpartyrock.aws%2F%3Ffbclid%3DIwZXh0bgNhZW0CMTAAAR2SQQKb5T6ae02Mbwdjm856u3iV1b0vQhkwtLUqXsVKZwxBu6_El1sPfW4_aem_Rgj7xOeUwqXOtBNsmA7L4Q&amp;h=AT0AbVDo7sC0DF9B6rppP18UU4T04kryY2lpUDuRtiW-AoEP1DJD_Y0AUfvF0qFXTrJnSj9s4VLUtRotiv2G2jaPYjbm7av56tBJrX5cgNG9GeFViNz1J_gy9Tj60OjZbqoNVPEdQQSUmFjn3Qhp&amp;__tn__=-UK-R&amp;c[0]=AT0IeVAG-LWo9ceywkQd1UuC3t-7u3dHNLGzjm_jboeuuGJU8fVT_4FSBZNpmXwqtPGONo19fOcYUb3oLQO06SSlOByA9Q3J-B4vwvlpLgm9iTVd7Y4x3j54g6bOm-sXPZz61de3Leck_wEz4ry6EaYB9KgoSaZ_fQquo62HB2o23MBJ_w1C">https://partyrock.aws</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G1nUoTC_bwZoKdHa" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yt-lM_5ndzBiMfTS" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GF8jJa3sbWcnv8jj" /></figure><p>โอเคครับ ต่อมาผมจะมาพูดถึงงาน AWS Code the Future โดยตัวงานครั้งนี้มาใน Concept: <strong>Build and Scale GenAI with AWS</strong></p><p>ซึ่งตัวงานบอกเลยครับว่าฟังสนุกไม่น่าเบื่อไม่ได้เป็นเชิงแนวเราฟังอาจารย์พูดเลคเชอร์ แต่เป็นการฟังแล้วคิดตาม แถม Speaker แต่ละคนก็พูดได้สนุกและเข้าใจง่ายมากๆ แต่ให้ไม่รู้จักหรือไม่เคยทำ GenAI มาก่อนก็สามารถฟังและเข้าใจได้ง่ายๆ</p><p>โดยงานนี้ Services หลักๆที่น่าสนใจคือ <strong>Amazon Bedrock</strong>, <strong>Amazon PartyRock</strong>, <strong>Amazon Q Developer</strong></p><h3><strong>Amazon Bedrock, Amazon Q Workshop</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*igthtaCMuL7gLzAm.png" /><figcaption><a href="https://aws.amazon.com/blogs/awsforsap/power-your-business-with-secure-and-scalable-generative-ai-services-from-aws-and-sap/">Power your business with secure and scalable generative AI services from AWS and SAP | AWS for SAP (amazon.com)</a></figcaption></figure><p>โดยผมจะพูดตัว Workshop Track2 นะครับ ในหัวข้อ “<strong>Amazon Bedrock, and Amazon Q” </strong>ซึ่ง Track นี้เป็น Track ที่อาจจะต้องการคนที่คุ้นเคยกับ ตัว AWS Cloud จะสามารถเข้าใจและทำ Workshop ไปได้แบบลื่นไหล แต่สำหรับคนที่อาจจะยังไม่คุ้นเคยไม่เป็นไรเพราะมี พี่ๆ Staff AWS ให้ความช่วยเหลือและซัพพอร์ทกันดีมากๆ</p><p>ซึ่งทาง AWS Thailand จะสร้างตัว AWS Workshop Studio ซึ่งเราสามารถทำตัว Workshop นี้ได้ซึ่งมีเวลา 3 วันก่อนที่จะ Account ที่ทาง AWS สร้างให้จะหมดเวลาลง (แต่เอาจริงๆใช้เวลาไม่เกิน 1 วันก็ทำเสร็จแล้วครับ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g54lNHwSyRoBYBumEKRkrw.png" /><figcaption>ตัวอย่างหน้า AWS Workshop Studio</figcaption></figure><p>โดยใน Track2 ก็จะได้ทำตัว <strong>Module2 </strong>และ <strong>Module3 </strong>ซึ่งมีเวลา 2 ชม. แต่ถ้าใครทำไม่เสร็จก็สามารถกลับไปทำต่อที่บ้านได้ครับ</p><p>ซึ่งในตัว Module2 เราสามารถสร้าง Application: Building a Text to Image Application</p><p>โดยตัว Workshop จะสอนการใช้ Playground ของ Amazon Bedrock (ใช้งานง่ายมากๆ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /><figcaption>ตัวอย่างการ Selection Model ใน AWS Bedrock</figcaption></figure><p>โดยในตัว Workshop จะมีการเปิด VSCode Code-Server ซึ่งเราสามารถเขียนและรันโค้ดได้เลย สะดวกสบายมากๆ ยิ่งผสมกับ Amazon Q บอกเลย Amazing!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0aY-FLnfl4Bg_NdY" /></figure><p>ว่าแต่ <strong>Amazon Q Developer</strong> คืออะไร?</p><p>Amazon Q Developer คือผู้ช่วย AI ที่ออกแบบมาเพื่อช่วยเหลือในการพัฒนาโปรแกรมและการใช้งาน AWS โดยใช้ปัญญาประดิษฐ์จาก Amazon Bedrock ซึ่งมีฟีเจอร์สำคัญตามนี้:</p><ol><li><strong>การสร้างและเติมโค้ด</strong>: ให้คำแนะนำและเติมโค้ดแบบเรียลไทม์ ตั้งแต่โค้ดส่วนย่อยไปจนถึงฟังก์ชันเต็มรูปแบบตามความคิดเห็นและโค้ดที่มีอยู่แล้วของผู้ใช้</li><li><strong>การแก้ปัญหาและสนับสนุน</strong>: ช่วยวินิจฉัยและแก้ไขข้อผิดพลาด แนะนำบริการของ AWS และให้แนวปฏิบัติที่ดีที่สุดโดยตรงในสภาพแวดล้อมการพัฒนาหรือ AWS Console</li><li><strong>การปรับปรุงโค้ด</strong>: ช่วยอัพเกรดโค้ดเก่า เช่น เปลี่ยนแอปพลิเคชันจาก Java เวอร์ชัน 8 เป็น 17 และเพิ่มการปฏิบัติที่ดีที่สุดในด้านความปลอดภัยและประสิทธิภาพ</li><li><strong>การสแกนความปลอดภัย</strong>: สแกนโค้ดเพื่อหาช่องโหว่และเสนอวิธีแก้ไข</li></ol><p>โดยใน Workshop นี้เราจะใช้ตัว Amazon Q ในการปรับโค้ดและให้ช่วยอธิบายโค้ดจากโค้ด Base จากทางตัว Workshop (<a href="https://github.com/build-on-aws/gen-ai-workshop">https://github.com/build-on-aws/gen-ai-workshop</a>)</p><p>โดยจะใช้ตัว streamlit ในการจำลอง UI บน Website</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*KzD9zgmlG3f3fLc1" /><figcaption>ตัวอย่าง Application Text to Image ที่สร้าง Amazon Bedrock + Amazon Q</figcaption></figure><p><strong>Module 3: Chat with your Documents</strong></p><p>โดย Module นี้เราจะได้ลองทำ RAG โดยใช้ Amazon Bedrock สร้าง Chatbot จาก Documents ของผู้ใช้งานเอง แล้วมันสำคัญยังไง?</p><p>เพราะ RAG นอกจากทำให้ลดการเกิด Hallucination แถมยังทำให้ตัว Chatbot สามารถ ตอบคำถามข้อมูลเชิง Real-Time ได้อย่างเช่น ถามว่าวันนี้อุณหภูมิที่กรุงเทพกี่องศาเซลเซียส ถ้าเราไม่ได้เชื่อม RAG กับตัว Chatbot เราตัว Chatbot ก็จะไม่สามารถตอบคำถามได้นอกจากเราจะเชื่อมกับข้อมูลอย่างเช่น Weather API</p><p>โดยในตัว Module3 นี้เราจะได้ทำครบ Pipeline เริ่มต้นจากการ Build RAG เข้าในไปตัว Bedrock ผ่าน <a href="https://aws.amazon.com/bedrock/knowledge-bases/">Knowledge Bases</a> และการสร้าง Agent, Action groups ซึ่งหลังจาก Apply ทุก Method ตัว Chatbot ของเราก็จะเก่งกาจและสุดยอด!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/0*D09pg8g3gsRvbCj0" /><figcaption>ตัวอย่าง Flow “chat with your documents”</figcaption></figure><p>ซึ่งใครสนใจ สามารถไปอ่านข้อมูลเพิ่มเติมตามลิงค์ข้างล่าง หรือ สอบถามในตัวกลุ่ม AWS User Group (Thailand)</p><p><a href="https://aws.amazon.com/bedrock/knowledge-bases/">Retrieval Augmented Generation (RAG) — Knowledge Bases for Amazon Bedrock — AWS</a></p><h3>สรุปงาน Code the future by AWS</h3><p>นอกจากตัว Workshop ที่กล่าวมา ยังมีกิจกรรมอีกมากมายอย่างเช่น Session การพูดของ Dr.Pan, Donnie และ staff AWS คนอื่นๆที่บรรยายในหัวข้อ Prompt Engineering, GenAI และ กิจกรรม KAHOOT, Lucky Draw สุดท้ายนี้ผมขอขอบคุณคุณ Wit จากกลุ่ม AWS User Group (Thailand) และ Staff จากทาง Amazon ที่จัดกิจกรรมที่สนุกและได้รับความรู้แบบนี้ ในอนาคตอยากให้มีอีกและอยากให้คนที่สนใจด้านนี้เข้ามาลองร่วมงานดูครับ รับรองไม่ผิดหวังแน่นอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FvndzwuoOW68mvMc" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ojuwkF6O01Wgiovm" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wE7UL1Q7s_6sl9Db" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DQ8cSqUIQhoBhPgs" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f410567672e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving Small Fruit Detection: Zero-Shot RT-DETR vs. YOLO-WORLD Using Patch-Based Techniques]]></title>
            <link>https://medium.com/@spped2000/improving-small-fruit-detection-zero-shot-rt-detr-vs-yolo-world-using-patch-based-techniques-42afbeae7335?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/42afbeae7335</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[rt-detr]]></category>
            <category><![CDATA[zero-shot-learning]]></category>
            <category><![CDATA[yolo]]></category>
            <category><![CDATA[yolo-world]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Fri, 28 Jun 2024 09:34:02 GMT</pubDate>
            <atom:updated>2024-06-28T10:22:48.184Z</atom:updated>
            <content:encoded><![CDATA[<p>To make things clearer and easier to follow, I’ll split this into two main sections. First, we’ll dive into <strong>RT-DETR</strong> and the <strong>YOLO-WORLD</strong> model. Then, we’ll move on to talk about <strong>patch-based</strong> techniques like <strong>SAHI </strong>and other similar methods. Finally, I’ll wrap up with the results.</p><p>Now let’s talk about RT-DETR first and why it’s so cool!</p><h3>RT-DETR: A Real-Time End-to-End Object Detector</h3><p><a href="https://github.com/lyuwenyu/RT-DETR?tab=readme-ov-file">lyuwenyu/RT-DETR: [CVPR 2024] Official RT-DETR (RTDETR paddle pytorch), Real-Time DEtection TRansformer, DETRs Beat YOLOs on Real-time Object Detection. 🔥 🔥 🔥 (github.com)</a></p><p>The researchers who created RT-DETR wanted to make a <strong>super fast</strong> object detection system that could identify things in images really accurately. They looked at two main approaches:</p><ol><li><strong>DETR </strong>models — These are pretty cool because they can detect objects without needing a bunch of extra steps like <strong>non-max suppression</strong>. But the problem is they are computationally expensive, so they run <strong>slow</strong>.</li><li><strong>YOLO</strong> models — These are known for being <strong>super fast</strong>, but they don’t always get the <strong>best accuracy</strong>.</li></ol><p>So the RT-DETR team came up with some clever ideas to make a DETR-based model that could beat the YOLOs in both <strong>speed and accuracy</strong>:</p><ul><li>They made the encoder part of the model more efficient by separating the processing of features at different scales. This let it run faster.</li><li>They also found a smart way to pick the initial object guesses that get fed into the decoder part of the model. This improved the accuracy.</li><li>Another neat thing is RT-DETR lets you easily adjust the speed by changing one setting, without having to retrain the whole model.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKk9OTbsODyZUt1eUtf5pg.png" /><figcaption>. Overview of RT-DETR (<a href="https://arxiv.org/pdf/2304.08069">2304.08069 (arxiv.org)</a>)</figcaption></figure><h3>YOLO-World: Zero-Shot Object Detection</h3><p><a href="https://github.com/AILab-CVC/YOLO-World">AILab-CVC/YOLO-World: [CVPR 2024] Real-Time Open-Vocabulary Object Detection (github.com)</a></p><ul><li>Can identify objects in images <strong>without being trained</strong> on them first using “<strong>zero-shot learning</strong>”</li><li>Works by combining vision models (great at analyzing images) with language models (great at understanding text)</li><li>You provide an image and a description of what you want it to detect, and it figures out what the object is</li><li>Uses the faster YOLO architecture for real-time performance without sacrificing accuracy</li><li>Overcomes limitations of previous zero-shot detectors that used slow, complex Transformer models</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nK7vdagvzlocSfAM" /><figcaption>Overview of YOLO-WORLD (<a href="https://arxiv.org/pdf/2401.17270">2401.17270 (arxiv.org)</a>)</figcaption></figure><p><strong>Test image</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9C8jTfQYcwgcGFkr2B-MVw.jpeg" /><figcaption>longan test image capture by drone</figcaption></figure><h3>Prediction use YOLO-WORLD (not including Patch-Based)</h3><p>Model: <strong>yolov8x-worldv2.pt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__UVjHpfmMUCPATtG7OaGQ.png" /></figure><p><strong>Result (Suck!! still same the original image)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*9C8jTfQYcwgcGFkr2B-MVw.jpeg" /></figure><h3>Prediction use YOLO-WORLD (Use SAHI)</h3><p>Model: <strong>yolov8x-worldv2.pt (same model)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYwfKu5ycp-oxSUN8XciDw.png" /></figure><p><strong>Result (better but suck!!)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7g0IMboGd9I9ZW761vQlQ.png" /></figure><h3>Prediction use RTDETR and RTDETR Patch-Based</h3><p>Basic RTDETR Inference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ryKhiqLImiaUePvVuhUxBg.png" /></figure><p>RTDETR Patch-Based Inference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFZ_zvuaq2CO_xxosJBgSQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42afbeae7335" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[YOLOV9 Instance Segmentation Custom Dataset Training Cool Performance!!]]></title>
            <link>https://medium.com/@spped2000/yolov9-instance-segmentation-custom-dataset-training-cool-performance-ef2fc8601499?source=rss-47208b7dc832------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef2fc8601499</guid>
            <category><![CDATA[instance-segmentation]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[yolov9]]></category>
            <category><![CDATA[segmentation]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Natdhanai Praneenatthavee]]></dc:creator>
            <pubDate>Thu, 28 Mar 2024 20:11:40 GMT</pubDate>
            <atom:updated>2024-03-28T20:11:40.471Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This article was written on 29 March 2024, so there may be changes in the future.</strong></p><p><a href="https://github.com/WongKinYiu/yolov9"><strong>YoloV9 official GitHub</strong></a></p><p>Before we proceed, let me introduce you to <strong>YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information</strong>, which was recently released on 29 February 2024, according to the research paper <a href="https://arxiv.org/pdf/2402.13616.pdf">2402.13616.pdf (arxiv.org)</a></p><p>You should read the actual paper on <strong>YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information to understand it yourself </strong><a href="https://arxiv.org/pdf/2402.13616.pdf">2402.13616.pdf (arxiv.org)</a></p><p>What I find interesting is the <strong>Generalized Efficient Layer Aggregation Network (GELAN)</strong>. Let’s plan to go into more depth on the details next time.</p><p>Alright, I think everyone is probably quite familiar with YOLO by now, and is always excited when a new version comes out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*iNU9gcbCfinM0YV5uDwFzw.png" /><figcaption>YOLOV9 Performance ref.(<a href="https://arxiv.org/pdf/2402.13616.pdf">2402.13616.pdf (arxiv.org)</a>)</figcaption></figure><p><a href="https://github.com/WongKinYiu/yolov9/tree/main"><strong>Instance Segmentation</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpIfekzd6pXrsRQ4Ee2QpQ.png" /><figcaption><a href="https://github.com/WongKinYiu/yolov9/tree/main">Segmentation Teaser</a></figcaption></figure><p>Instance Segmentation model that supported now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*G2vKP1gfahJ1o_oxsxVMkg.png" /><figcaption><a href="https://github.com/WongKinYiu/yolov9/tree/main">Instance Segmentation model</a></figcaption></figure><p>Today I choose <strong>GELAN-C-SEG </strong>for demonstration.</p><p>First you choose looking to official google colab for guideline.</p><p><a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov9-object-detection-on-custom-dataset.ipynb">train-yolov9-object-detection-on-custom-dataset.ipynb — Colaboratory (google.com)</a></p><p>Setup first (Install YoloV9)</p><pre>!git clone https://github.com/SkalskiP/yolov9.git<br>%cd yolov9<br>!pip install -r requirements.txt -q<br>!pip install Pillow==9.5.</pre><p>Install <strong>gelan-c-seg </strong>weight model</p><pre><br>!wget -P {HOME}/weights -q https://github.com/WongKinYiu/yolov9/releases/download/v0.1/gelan-c-seg.pt<br>and glan-c-seg.yaml also</pre><p><strong>Preprocess</strong></p><p>-Data structure <strong>YoloV9</strong> same as <strong>YoloV8</strong></p><p>-You can use data.yaml before for using in YoloV9.</p><p>-Same .txt YoloV8 format for segmentation</p><p><strong>For training</strong></p><p>Example:</p><pre>!python yolov9/segment/train.py --workers 8 --device 0 --batch 2  --data coffee_seg.yaml --img 640 --cfg yolov9/models/segment/gelan-c-seg.yaml --weights weights/gelan-c-seg.pt --hyp hyp.scratch-high.yaml --no-overlap --epochs 500 --close-mosaic 10</pre><p>If everything ok, it should be same below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TbvDn-gS_RrHEFqrjKHdDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6j7y6R2nQxR4Ue_v8xGLhg.png" /></figure><p>Instance Segmentation Result Example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*zIQvZuCCe0znMzYrX4mhAQ.png" /></figure><p>Conclusion</p><p>I have already compared it with YOLOv8. The results are quite amazing, I think. YOLOv9 performs significantly better than YOLOv8.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef2fc8601499" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>