ATL/COM备忘

330 篇文章 4 订阅 ¥19.90 ¥99.00
这篇博客详细介绍了ATL/COM开发的各种关键概念,包括本地和外部的使用,连接点,智能指针,注册COM对象的方法,以及如何处理BSTR、字符串转换和属性类型。还涵盖了调试,内存泄漏跟踪,以及如何手动注册和卸载COM对象等实用技巧。
摘要由CSDN通过智能技术生成

ATL/COM

http://www.exogenesis.org/notes/atlcom.html#registering

Local
External

Types allowed for Properties

COM value typeCOM reference typeSystem type
boolbool *System.Int32
char, smallchar *, small *System.SByte
shortshort *System.Int16
long, intlong *, int *System.Int32
Hyperhyper *System.Int64
unsigned char, byteunsigned char *, byte *System.Byte
wchar_t, unsigned shortwchar_t *, unsigned short *System.UInt16
unsigned long, unsigned intunsigned long *, unsigned int *System.Int32
unsigned hyperunsigned hyper *System.UInt64
floatfloat *System.Single
doubledouble *System.Double
VARIANT_BOOLVARIANT_BOOL *System.Boolean
void *void **System.IntPtr
HRESULTHRESULT *System.Int16 or System.IntPtr
SCODESCODE *System.Int32
BSTRBSTR *System.String
LPSTR or [string, ...] char *LPSTR *System.String
LPWSTR or [string, ...] wchar_t *LPWSTR *System.String
VARIANTVARIANT *System.Object
DECIMALDECIMAL *System.Decimal
DATEDATE *System.DateTime
GUIDGUID *System.Guid
CURRENCYCURRENCY *System.Decimal
IUnknown *IUnknown **System.Object
IDispatch *IDispatch **System.Object
SAFEARRAY(type)SAFEARRAY(type) *type[]

Support for getting properties from HTML's OBJECT PARA

Do the following steps to enable PARAM support.

The HTML
The ActiveX controls .h file
  • add this to the base classes
    public IPersistStreamInitImpl<scenegraphxcontrol>,
  • In the section starting with
    BEGIN_COM_MAP(SceneGraphXControl)
    add
    COM_INTERFACE_ENTRY(IPersistPropertyBag)

String Conversion

Macro 
CW2A asciiStr( wideStr)

Text Field

  • Set the Text in a text field SetDlgItemText( IDC_EDIT_ServerURL, CComBSTR_URL.m_str);

Radio Button

  • This checks a radio button, but causes a click event:
    SendDlgItemMessage( IDC_RADIO_ServerNeededNo, BM_CLICK);
  • This checks a radio button, and shouldn't cause an event, but wouldn't work for me:
    SendDlgItemMessage( IDC_RADIO_ServerNeededYes, (WPARAM)BST_CHECKED, TRUE);

Connection Points

Connection Point Example

Note: here is a good article about adding a connection point to an existing COM object:
The title is very misleading "Dispinterface vs. Events and Runtime Sinks" http://www.codeguru.com/Cpp/COM-Tech/atl/article.php/c3573/


STDMETHOD and STDMETHODIMPL


// proto:
STDMETHOD(put_Sides)(SHORT newVal);

// impl:
STDMETHODIMP CPolyCtl::put_Sides(SHORT newVal)
{
    return S_OK;
}

Registering Via Explorer Right Click

register_in_menu.reg

Make a .reg file containing this:


REGEDIT4

[HKEY_CLASSES_ROOT/.dll]
@="dllfile"

[HKEY_CLASSES_ROOT/.ocx]
@="ocxfile"

[HKEY_CLASSES_ROOT/.olb]
@="olbfile"

[HKEY_CLASSES_ROOT/.exe]
@="exefile"


[HKEY_CLASSES_ROOT/dllfile/shell/Register/command]
@="regsvr32.exe %1"

[HKEY_CLASSES_ROOT/ocxfile/shell/Register/command]
@="regsvr32.exe %1"

[HKEY_CLASSES_ROOT/olbfile/shell/Register/command]
@="regsvr32.exe %1"

[HKEY_CLASSES_ROOT/exefile/shell/Register/command]
@="%1 /register"

[HKEY_CLASSES_ROOT/dllfile/shell/Register (Silent)/command]
@="regsvr32.exe /s %1"

[HKEY_CLASSES_ROOT/ocxfile/shell/Register (Silent)/command]
@="regsvr32.exe /s %1"

[HKEY_CLASSES_ROOT/olbfile/shell/Register (Silent)/command]
@="regsvr32.exe /s %1"



[HKEY_CLASSES_ROOT/dllfile/shell/UnRegister/command]
@="regsvr32.exe /u %1"

[HKEY_CLASSES_ROOT/ocxfile/shell/UnRegister/command]
@="regsvr32.exe /u %1"

[HKEY_CLASSES_ROOT/olbfile/shell/UnRegister/command]
@="regsvr32.exe /u %1"

[HKEY_CLASSES_ROOT/exefile/shell/UnRegister/command]
@="%1 /unregister"

[HKEY_CLASSES_ROOT/dllfile/shell/UnRegister (Silent)/command]
@="regsvr32.exe /u /s %1"

[HKEY_CLASSES_ROOT/ocxfile/shell/UnRegister (Silent)/command]
@="regsvr32.exe /u /s %1"

[HKEY_CLASSES_ROOT/olbfile/shell/UnRegister (Silent)/command]
@="regsvr32.exe /u /s %1"

Registering Via Command line


regsvr32.exe
c:/windows/system32/regsrv32.exe

Registering a COM object


Registry Manipulation


	CRegKey key;
	retval = key.Open( HKEY_CLASSES_ROOT,
		"CLSID//{0C234ACE-FF67-49F7-ABFD-C62A8D1F94EF}//InprocServer32", KEY_READ);
	TCHAR buf[1000];
	key.QueryStringValue( "", buf, &nChars);

STL issue

Some stl container types need the operator& of a object to return its address. But CComBSTR and other classes override it. So you need to make them 'unoverride it'. To do this, wrapthen in CAdapt<>, example: std::list<CAdapt<CComBSTR>>


Creatablity, making an Interface not creatable from outside

  • Use the macro OBJECT_ENTRY_NON_CREATEABLE_EX_AUTO( clsid, class)
  • Delete the base class CComCoClass<...> from the class
  • Remove the classes .rgs file
  • Add noncreatable to the [ ] section just above coclass in the .idl file
  • Add a forward declaration of your interface in the .idl file, right after the imports. Make it look like this: interface INonCreatable;
  • Since no CComCoClass, define a Category Map:
    BEGIN_CATEGORY_MAP(classname)
    END_CATEGORY_MAP()
  • Add a Method like this from the place you want the interface to be created at:
    STDMETHODIMP CCreatorObject::CreateIt( INonCreatable **ppNonCreatable) {
    	*ppNonCreatable = NULL;
    	return CoComCreator< CComObject< CNonCreatable>>::
    		CreateInstance( NULL, IID_INonCreatable, reinterpret_cast<void**>(ppNonCreatable));
    }
  • Note: It is recomended that
    CComObject<CNonCreatable>::CreateInstance(...) be used instead of
    CoComCreator< CComObject< CNonCreatable>>::CreateInstance(...) if the newly created class needs special initialization before it is returned. (?something about this version of CreateInstance not incrementing the Reference count.

Categories

Categories are used to group COM Objects. For Example you can say your object belongs to CATID_MyCoolControls - you can have the thing that uses it look for all the members of CATID_MyCoolControls and load only them


// defining a CATID:
struct __declspec(uuid("{EA4A7D89-7E4E-4450-B607-4E44E1F71CFD}")) CATID_MyCoolControls;

// Put a map like this COM classes header file somewhere:
BEGIN_CATEGORY_MAP(MyControl5)
	IMPLEMENTED_CATEGORY(__uuidof(CATID_MyCoolControls))
END_CATEGORY_MAP()

Licensing, adding support for

Add a DECLARE_CLASSFACTORY2({classname}) macro to your Interfaces .h file. Example:


class ATL_NO_VTABLE DvoResourceManager :
	...
{
public:
	DvoResourceManager();

DECLARE_REGISTRY_RESOURCEID(IDR_DVORESOURCEMANAGER)
DECLARE_CLASSFACTORY2(DvoResourceManager)

BEGIN_COM_MAP(DvoResourceManager)
	...

Singleton, Making an Interface one

Add a DECLARE_CLASSFACTORY_SINGLETON({classname}) macro to your Interfaces .h file. Example:


class ATL_NO_VTABLE DvoResourceManager :
	...
{
public:
	DvoResourceManager();

DECLARE_REGISTRY_RESOURCEID(IDR_DVORESOURCEMANAGER)
DECLARE_CLASSFACTORY_SINGLETON(DvoResourceManager)

BEGIN_COM_MAP(DvoResourceManager)
	...

#import

#import "{name}.tlb" provides the following: (Note: you can see this implementation of this stuff in the .tli file)

  • Puts everything in a namespace named after the typelibrary name.
  • Wrapper to return [retval] directly and throws an exception if the HRESULT is not SUCEEDED
  • Smart Pointers to interfaces
  • Wraps VARIANT to _variant_t and BSTR to _bstr_t
  • Allow [propget] and [propput] methods to be accessed like data members (as well as functions)
  • Doesn't define things like DVOCLASSESLib::CLSID_Quad by default you need to specify the #import attribute named_guids
    Example: #import "DvoClasses.tlb" named_guids
    It is preferable to use: __uuidof( DVOCLASSESLib::Quad)

// pseudo .idl
interface Test1
{
	[id(1), helpstring("method Add")] HRESULT Add( [out] LONG* pOut, LONG a, LONG b);
	[propget, id(2), helpstring("")] HRESULT val([out, retval] short *pVal);
	[propput, id(2), helpstring("")] HRESULT val([in] short val);
}

coclass Test
{
	[default] interface Test1;
	interface Test2;
}

// pseudo .cpp file
#import "Test.tlb"

try {
	// smart pointer
	Test::ITest1Ptr p( __uuidof( Test::Test1));
	// returns a value and throws an exception if failure
	int sum = spITest->Add( 5, 5);
	// Access properties as data members
	int val = spITest->val;
	spITest->val = 37;
}
catch (const _com_error & Err) {
	// err number is:
	Err.Error();
}

Note: you don't always need enable exception handling in the compiler (Project Properties | C/C++ | Code Generation | Enable C++ Exceptions), because that has to do with unwinding locally declared objects.


Initialization (for class data, and for instance data)

For Class Data

For each interface entry in coclass (in the .idl file) the method ObjectMain( bool starting) will be called. It is called with true on startup and false on shutdown. These are called once when the COM server starts up and shuts down. Override it do do your own startup initialization and shutdown cleanup.

For Instance Data

Since Interface methods cannot be called from the constructor, due to no vtable until after the constructor returns; Initialization should occur in FinalConstruct (which should be defined as an empty inline method in the COM classes header file)

Note: FinalConstruct MUST return S_OK on success (any other success code is considered a failure)

Another good thing about using FinalConstuct, is that you can fail out of it to prevent your object from being returned (I assume it just destroys it)

Beware of the gotcha 'Premature deletion of an object in FinalConstruct'

There is also a FinalRelease, but I don't know why you would need to use it instead of the destructor.


Gotchas

Enum, cannot get to it when using #import "file.tlb"

It is reached by {Namespace}{enum val name} be careful not to use {Namespace}::{enum typedef name}::{enum val name}

ComPtr not being found even though type lib is imported

#import "name.tlb" always defines a namespace, use the namespace to get to the ComPtr you want.
The namespace is named after the library name (which can be found in the .idl file)

... unresolved external symbol _main

ATL (by default) doesn't include the full CRT (C Runtime library), and you hit some code that needs part of it that isn't available. Remove the definition of _ATL_MIN_CRT so that it will include the full CRT. It looks like the way to turn this off is now from Project Properties | General | Minimize CRT Use in ATL

Premature deletion of an object in FinalConstruct

If FinalConstruct causes an AddRef() and a Release() to be called it will delete itself (this may happen if you do a QueryInterface in FinalConstruct). To prevent this from happening, add this macro to your COM classes header file: DECLARE_PROTECT_FINAL_CONSTRUCT() (this seems to be added by default now)

SaveAllChanges Failed

The .tlb is probably loaded in some app, and cannot be written.


Registering a COM object Manually

  1. Open the .idl file and copy the coclass guid into the clipboard
  2. Run regedit
  3. Right click on HK_CLASSES_ROOT/CLSID and choose New | Key
  4. Paste the coclass guid (Make sure the value is surrounded by braces { } (just like the other entries)
  5. Select the newly created key, and double click on Default to edit it
  6. Set the Value to the name of coclass
  7. Add a new key under the just created key, and name it InprocServer32
  8. Set the Default value to the fully specified path of the COM .dll
  9. Right click in the right hand pane to add a new String value to InprocServer32
  10. Name the String ThreadingModel and set its value to Apartment
  11. You should be able to see the COM object in the OLE/COM Object Viewer it is OleView.exe or in the tools menu of Visual Studio. It will be at Object Classes | All Objects

CLSID's (Class IDs)


//CLSID if using import
#import "Something.tlb"
// Note: use the class name, not the Interface name ISomething
// you can find it in the .idl file as the coclass value
__uuidof(Something)

//CLSID from a String
CLSID clsId;
CLSIDFromString(L"{145AE31A-E4AE-4400-A485-A39900E03C84}", &clsId);

//CLSID from ProgID
CLSIDFromProgID(); // inverse is: ProgIDFromCLSID();

Return Values

S_OK
S_FAIL
if (SUCCEEDED(hr))
if (FAILED(hr))

Debugging

Debug Macros
MacroPurpose
_ATL_DEBUG_INTERFACESShows Interface Leaks when _Module.Term is called.
_ATL_DEBUG_QIShows when QueryInterface is called.
ATLTRACE2See Micosofts docs, controls lots of settings.
Debugging Reference Counts
  1. Make sure _ATL_DEBUG_INTERFACES is defined before the atl headers are included (best to just put it in stdafx.h)
  2. Run then exit your program in debug mode. When you finish, the output window in Visual Studio with show a line like:
    QIThunk - 10        	Release :	Object = 0x01d1aa6c	Refcount = 0	CGLX2DOGL - IDvoGLX2D
  3. Find the QIThunk # for the Object you want to look at references counts for (it is 10 in the example line above)
  4. Modify your code, so that somewhere before that object is first created you do this:
    _AtlDebugInterfacesModule.m_nIndexBreakAt = {QIThinkNumberGoesHere};
  5. Now DebugBreak(); will be called when there is Reference count activity on the specified Object Class.
  6. So just run again in the debugger, and watch the debugging happen.
  7. NOTE: it is good to put a breakpoint in atlbase.h in bool CAtlDebugInterfacesModule::DumpLeakedThunks() at the line m_aThunks.RemoveAll();, then it will break just after dumping the leaked list to the output window (so you don't have to scroll around for it).

_AtlDebugInterfacesModule is of type CAtlDebugInterfacesModule there are some other fields you can access in it ( m_nIndexQI, m_cs, and m_aThunks )

It seems like there is a way to remove a thunk from _AtlDebugInterfacesModule at runtime (from something I read about it).

Here is the article that tipped me off about this way to debug reference counts: http://codeguru.earthweb.com/atl/atldebug.shtml


BSTR

WARNING: Do NOT make a BSTR like this: BSTR str = L"Hello";. While it may work in many cases, it is not right and will not delete correctly.

Storage Format

BSTRs are pointers to the 5th byte of a memory block. When they are 'free()ed', they are 'free()ed' from 4 bytes before where they point to. They start with a count of the number of bytes of character data they contain, excluding 2 terminating 0 bytes at the end of the string.

Example Usage

BSTR str1 = SysAllocString( L"Hello");
BSTR str2 = SysAllocString( OLESTR("Hello"));

SysFreeString(str2);
SysFreeString(str1);
Functions
BSTR SysAllocString( WideString);Takes the Wide Char string, and copies it into a newly allocated BSTR
BSTR SysAllocStringLen(?)
BSTR SysAllocStringByteLen(?)
BSTR SysReAllocString(?)
BSTR SysReAllocStringLen(?)
???? SysStringLen(?)
???? SysStringByteLen(?)
???? VectorFromBstr(?)SAFEARRAY Vector from a BSTR
???? BstrFromVector(?)BSTR to a SAFEARRAY Vector
???? VarBstrCat(?)(undocumented) Concatinates
???? VarBstrCmp(?)(undocumented)Compares 2 BSTRs and returns one of:
VTCMP_LT, VTCMP_EQ, VTCMP_GT, VTCMP_NULL
SysFreeString( BSTR);
With ATL

Try using CComBSTR

With MFC
CString( BSTR);Construct directly from a BSTR
?? BSTR CString::AllocSysString();To Read it out
?? BSTR CString::SetSysString(?);To realloc

CString str1( BSTR bstr);
Other

Microsoft Visual C++® version 5.0 and later support the _bstr_t class to provide a more sophisticated wrapper for BSTR. In addition to the functionality of CComBSTR, _bstr_t also provides comparison operators. In addition, _bstr_t avoids allocating extra BSTR objects by using reference counting—more efficient, but not as thin a wrapper as the CComBSTR.

You can also use the C++ Standard Library's wstring class, but you'll have to convert to and from BSTR. You can convert from BSTR to wstring by constructing a new wstring object using the appropriate constructor. You convert to a BSTR by getting a pointer to the string wrapped by the wstring object and calling one of the COM APIs that allocate a BSTR, such as SysAllocString.

More Info
http://whidbey.msdn.microsoft.com/library/default.asp?url=/library/en-us/dnguion/html/drgui042099.asp

Adding Methods by Hand

  1. You need write permission on the .idl .cpp .h files.
  2. Add you method to the interface, like this:
    [id(15), helpstring("method DeleteIcon")]
    HRESULT DeleteIcon( [in] long IconHandle);
  3. To the .h file add a public prototype like this:
    STDMETHOD(DeleteIcon)( long iconHandle );
  4. To the .cpp file add the method, like this:
    STDMETHODIMP ClassName::DeleteIcon( long iconHandle)
    {
    	return S_OK;
    }
    
  5. It should compile now.

Connection Point Example

I made an ActiveX control in Visual Studio .NET as follows

  1. new ATL project (ConnectionPoint6)
  2. add class 'ATL Control' with options 'composite control' 'connection points' (JbpCon6)
  3. added a button and an event handler for the button
  4. added a method to ConnectionPoint6Lib|_IJbpCon6Events, it was called OnJBP and had 1 param BSTR named string1
  5. added connection point to CJbpCon6
  6. added Fire_OnJBP to the button event handler, like this Fire_OnJBP( CComBSTR( "this is the message"));

To Test from C#

  1. new C# application
  2. goto the graphical designer view
  3. choose "Customize toolbox" from the Components context menu
  4. check the box next to JbpCon6 Class
  5. Now JbpCon6 is in the list of components, so just add it to the form
  6. on the properties window click on the lightning bolt to be able to add a handler for OnJBP (double click 'OnJBP' to add a handler)

To Test from HTML

I made the html file to test the control look like this:


// NOTE: get the CLSID from coclass JbpCon6 uuid
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" 
	"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ATL 7.0 test page for object JbpCon6</title>
</HEAD>
<body>


<object 
	id="JbpCon6" 
	classid="CLSID:807C00B5-0A73-485F-81AC-8630EF2FCD41" 
	viewastext>
</object>

<script language="javascript" for=JbpCon6 event=OnJBP>
<!--
JbpCon6_OnClick()
//-->
</script>

<script id=clientEventHandlersJS language="javascript">
function JbpCon6_OnClick()
{
	alert("hello");
}
</script>

</body>
</HTML>

And the alert box would pop up when I hit the button (after an ActiveX warning box)


Smart Pointers

  • A smart pointer for IComThing is IComThingPtr and is found in the file: {somename}Tlb.h
  • it is instanced like this pLutFactory.CreateInstance( CLSID_DvoLutFactory);
  • In ATL smart pointers are Templates wrapping around _com_ptr_t
  • Use operator bool() const throw() to tell if a smart pointer is pointing to NULL
  • See #import for info on getting CLSID_NAME values, it is preferable to use __uuidof( DVOCLASSESLib::Quad)

#include "{???}Tlb.h"

// Connects on its own
{
  IComThingPtr spComThing;
	spComThing.CreateInstance( CLSID_ComThing);
	spComThing->foo();
	// or
	IComThing2Ptr spComThing2( CLSID_ComThing2); // ???
	spComThing2->foo();
}
// or Connects to an old style com object
{
	IComThing *pComThing = ...;
	IComThingPtr spComThing;
	// it adds a ref when it adds it
	spComThing = pComThing;
	spComThing->foo();
	// it removes a ref when it goes out of scope
}

// Switching Interfaces 'Casting'
IGooPtr spIGoo(__uuidof(MyObject));   // create object
spIGoo->Gunc();            // call method

IFooPtr spIFoo = spIGoo;   // QI different interface, same object
spIFoo->Func1();      // call method on new interface

Link Issues

if the linker cannot find something like: IID_IRasterBandCollection
make sure StdAfx.h contains something like: #include <idl/rdotlb.h>


SAFEARRAY info

See also VARIANT and SAFEARRAY info

When creating the SAFEARRAY:


SAFEARRAYBOUND *sab = new SAFEARRAYBOUND[2];
sab[0].lLbound = 0;
sab[0].cElements = pCalcBins; // least significant index
sab[1].lLbound = 0;
sab[1].cElements = pCalcBins; // most significant index

When reading the SAFEARRAY:


for ( j = 0; j < 3; j++) {
	for ( i = 0; i < pCalcBins; i++) {
		long indices[] = { i, j};  // { least significant, most significant }
		SafeArrayGetElement( psaOutLUT, indices, &val);
	}
}
SafeArrayCreate
SafeArrayCreateVector
SafeArrayCopy
SafeArrayCreateEx
SafeArrayCreateVectorEx
SafeArrayGetDim
SafeArrayGetLBound
SafeArrayGetUBound
SafeArrayGetElemsize
SafeArrayGetElement
SafeArrayPutElement
SafeArrayLock
SafeArrayAccessData
SafeArrayPtrOfIndex
SafeArrayUnlock
SafeArrayUnaccessData
SafeArrayRedim
SafeArrayDestroy
SafeArrayAllocDescriptor
SafeArrayAllocDescriptorEx
SafeArrayAllocData
SafeArrayCopyData
SafeArrayDestroyDescriptor
SafeArrayDestroyData
(undoc) SafeArraySetIID
(undoc) SafeArrayGetIID
(undoc) SafeArrayGetRecordInfo
(undoc) SafeArraySetRecordInfo
(undoc) SafeArrayGetVartype

VARIANT, Putting a SAFEARRAY into one


VARIANT v;
VariantInit( &v);                                 // Sets the Variant to VT_EMPTY
SAFEARRAYBOUND rgb [] = {100, 0};                 // numElements, lowerBounds
v.vt = VT_ARRAY | VT_I4;                          // Array of longs
v.parray = SafeArrayCreate(VT_I4, 1, rgb);        // Type, Dimensions, BoundsInfo
long *rgelems;                                    // Pointer for long elements
SafeArrayAccessData(v.parray, (void**)&rgelems);  // Get pointer to data and lock array
for (int c = 0; c < 100; c++)
    rgelems[c] = c;
SafeArrayUnaccessData(v.parray);                  // Release the lock on the array

// The VARIANT now owns the SafeArray, and will free it when VariantClear is called

VARIANT and SAFEARRAY info

Article: http://www.whooper.co.uk/excelvariants.htm


Deleting an Object

  1. Delete the files:
      {ClassName}.cpp
      {ClassName}.h
      {ClassName}.rgs
    
  2. Delete {ClassName}'s entries from the .idl file.
  3. Delete {ClassName}'s reference in resource.h (hmm, does _APS_NEXT_SYMED_VALUE need to be considered? I am assuming not)
  4. Delete {ClassName}'s from the .rc file
  5. Use regedit to remove {ClassName}'s stuff from

Thunking

Thunking, or how to get a classes this pointer through a static callback that has no place to save it as callback data.

You basically use the fact that a function pointer is an address that is called to jump into a function.

The change it so that it jumps into some assembly that you build, as opposed to the actual function start that it expects to jmp into.

For the WINDPROC case, you swap out the HWND parameter with the 'this' pointer you want. then you execute a jmp to the static WINDPROC of the class the 'this' belongs to.

At that point you cast the HWND parameter to a 'this' of the class the static function belongs to, and then you can call a member func with it.


Unregistering a Control


regsvr32 /u ./file.dll
// or
regsvr32 /u ./file.ocx
 
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
应用背景为变电站电力巡检,基于YOLO v4算法模型对常见电力巡检目标进行检测,并充分利用Ascend310提供的DVPP等硬件支持能力来完成流媒体的传输、处理等任务,并对系统性能做出一定的优化。.zip深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值