With the development of smart cities, the demand for artificial intelligence (AI) based services grows exponentially. The existing works just focus on cloud- edge or edge-device cooperative AI which suffers low learning efficiency of AI, while edge-to-edge cooperative AI is still an unresolved issue. Moreover, the existing researches concentrate on the computation offloading of the AI-based task, ignoring that it is a brain-like task performing sophisticated processing to raw data, which leads to the high latency and low quality of the learning services. To address these challenges, this paper proposes an on-demand learning offloading mechanism for edge-to-edge cooperative AI. Firstly, the principle of the learning capability and its offloading are proposed for the formal description of the learning resources migration. Secondly, the proposed mechanism realizes the bilateral learning offloading utilizing edge-to-edge and cloud-edge collaborations to handle AI-based tasks with high learning efficiency and resource utilization rate. Moreover, we model the edge-to-edge learning offloading allocation based on the concatenation of deep neural network (DNN) subtasks and their heterogeneous requirement of learning resources. Simulation results indicate the rationality and efficiency of the proposed mechanism.