cvconvnet.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003 downloading, copying, installing or using the software you agree to this
00004 license. If you do not agree to this license, do not download, install, copy or
00005 use the software.
00006 
00007 Contributors License Agreement
00008 
00009 Copyright© 2007, Akhmed Umyarov. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification,
00012 are permitted provided that the following conditions are met:
00013 - Redistributions of source code must retain the above copyright notice, this
00014 list of conditions and the following disclaimer.
00015 - Redistributions in binary form must reproduce the above copyright notice, this
00016 list of conditions and the following disclaimer in the documentation and/or
00017 other materials provided with the distribution.
00018 - The name of Contributor may not be used to endorse or promote products derived
00019 from this software without specific prior written permission.
00020 
00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00025 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00029 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00030 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 All information provided related to future Intel products and plans is
00032 preliminary and subject to change at any time, without notice.
00033 *****************************************************************************/
00034 
00035 
00044 #include <cassert>
00045 #include <iostream>
00046 #include <sstream>
00047 #include "cvconvnet.h"
00048 #include "cvsourceplane.h"
00049 #include "cvconvolutionplane.h"
00050 #include "cvsubsamplingplane.h"
00051 #include "cvgenericplane.h"
00052 #include "cvrbfplane.h"
00053 #include "cvconvnetparser.h"
00054 
00055 using namespace std;
00056 // Constructors/Destructors
00057 //  
00058 
00059 CvConvNet::CvConvNet ( )
00060 {
00061         m_creator = "undefined";
00062         m_name = "untitled";
00063         m_info = "";
00064 }
00065 
00066 CvConvNet::~CvConvNet ( )
00067 { 
00068         // Clean up all planes
00069         for (int i = 0; i < m_plane.size(); i++)
00070         {
00071                 assert( m_plane[i] != NULL );
00072                 delete m_plane[i];
00073         }
00074         m_plane.clear();
00075 }
00076 
00077 //  
00078 // Methods
00079 //  
00080 
00087 double CvConvNet::fprop (CvArr * input )
00088 {
00089         if ( (input == NULL) || !(m_plane[0]->setfmap(input)) )
00090         {
00094                 cerr << "ERROR: Wrong input image" << endl;
00095                 return -1.0;
00096         }
00097         
00098         // Iterate over all planes
00099         for (signed int i = 0; i < m_plane.size(); i++)
00100         {
00105                 m_plane[i]->fprop();
00106         }
00107 
00108         return cvmGet(m_plane.back()->getfmap(),0,0);
00109 }
00110 
00111 
00119 const CvMat *CvConvNet::getplane( std::string id )
00120 {
00121         map<string,int>::iterator itr = m_idmap.find(id); 
00122         assert( itr != m_idmap.end() );
00123 
00124         return m_plane[itr->second]->getfmap();
00125 }
00126 
00134 std::string CvConvNet::toString()
00135 {
00136         ostringstream xml;
00137         xml << *this;
00138         return xml.str();
00139 }
00140 
00141 
00146 int CvConvNet::fromString ( std::string xml )
00147 {
00148         return parse(xml, m_creator, m_name, m_info, m_plane, m_idmap);
00149 }
00150 
00151 
00152 ostream& operator<< (ostream& s, CvConvNet& n)
00153 {
00154         s << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
00155         s << "<net name=\"" << n.m_name << "\" creator=\"" << n.m_creator << "\"" << endl;
00156         s << "\t<info> " << n.m_info << " </info>" << endl;
00157         for (signed int i=0; i < n.m_plane.size(); i++)
00158         {
00159                 s << n.m_plane[i]->toString();
00160         }
00161         s << "</net>" << endl;
00162         return s;
00163 }
00164 
00166 istream& operator>> (istream& s, CvConvNet& n)
00167 {
00168         cerr << "*** ERR: operator >> is not implemented yet" << endl;
00169 }

Generated on Fri Aug 3 16:17:27 2007 for ConvNet by  doxygen 1.5.0